The Controller.
Now that we have our Files, Database and Model ready, lets get to the controller, where the REAL action takes place. Model --> <--Controller --> View! That's how it works!
There is already a controller that came with the CodeIgniter installation, 'welcome.php', we will stick to that but remove everything inside that file except the lines - '
class Welcome extends Controller {
}'
Lets start with our functions. This time again we just have 2 functions
- Index function , this is the default controller function in CodeIgniter.If you load your controller using URI eg:localhost/codeigniter/index.php/welcome , the index function is loaded unless you specify your function in the URI eg:localhost/codeigniter/index.php/welcome/functionname.Here's our index function-
function index()
That's explains all.
{
$this->load->Model('shoutmodel');//loading the model
$data['shout']=$this->shoutmodel->getshout();//loading the model function 'getshout()' and storing the 'getshout' function data as array in $data variable
$this->load->view('index',$data); //loading the view 'index.php' and sending stored data in $data variable to view
}
function shout()
{
$this->load->Model('shoutmodel');//loading the model
$this->shoutmodel->newshout();//loading the model function 'newshout()'
$data['shout']=$this->shoutmodel->getshout();//loading the model function 'getshout()' and storing the 'getshout' function data as array in $data variable
$this->load->view('index',$data) ;//loading the view 'index.php' and sending stored data in $data variable to view
}
class Welcome extends Controller {
function index()
{
$this->load->Model('shoutmodel');
$data['shout']=$this->shoutmodel->getshout();
$this->load->view('index',$data);
}
/*function index()
{
}*/
function shout()
{
$this->load->Model('shoutmodel');
$this->shoutmodel->newshout();
$data['shout']=$this->shoutmodel->getshout();
$this->load->view('index',$data) ;
}
}
i know its getting a little boring ... but guess what, its almost done!
TOWARDS THE LAST STEP...
Leave a comment for help !
No comments:
Post a Comment