<?php
class Helloworld extends Controller {
function Helloworld()
{
parent::Controller();
$this->load->model('helloworld_model');
}
function index()
{
$data = $this->helloworld_model->data();
$this->load->view('output',$data);
}
}
?>
explanation:
Remember the naming class must use capital letters at the beginning.
The script $ this-> load-> model ('helloworld_model') is used to access files named helloworld_model model.
The script $ data = $ this-> helloworld_model-> data (); used to call the function data () that existed at helloworld_model. Function has a return value that was then in the capacity into the variable $ data.
The script $ this-> load-> view ('output', $ data); used to call the view that output is accompanied by a variable named $ data in it.
4.Buatlah a model file and name it helloworld_model.php and place it in a folder system / application / models. Fill the file is as follows:
<?php
class Helloworld_model extends Model {
function Helloworld_model()
{
parent::Model();
}
function data()
{
$data['test'] = 'Hello World !!';
return $data;
}
}
?>
5.Make a view file and name it output.php and place it in a folder system / application / view. Fill the file is as follows:
<html>
<head>
<title>Hello World !!</title>
</head>
<body>
<h1><?=$test;?></h1>
</body>
</html>
6. Please access your browser eg http://localhost/CodeIgniter/
0 comments
Post a Comment