Codeigniter MVC structure

Hi everybody,would you like to know how Codeigniter works then lets discuss about it.

Codeigniter is a PHP framework which is built in a MVC structure.

Model  – All the database queries are written here.

View – All the htmls are used to be here .

Controller – We take the output from model and pass it to the HTML using an array variable.

 

class Example extends MY_Controller {

public function index()
{

$this->load->model(‘model_example’);

$data[‘info’] = $this->model_example->info($user_id);

$this->layout->view(‘example/index’,$data);

}

}

 

In the above example you can see that controller (example.php) takes the output from model (model_example) and passes it to the view index.php .

In the view you will get the array $info .You just need to print/echo that one .

This depends on individual level how they want to use the view.Few developers uses parse method while many uses load method.I would recommend the load method since the parse method first transfer those tags to php and then compile so you can understand which one is better.

Please discuss more about this if you want to share your views or you want to know anything regarding Codeginiter .

Leave a Reply

Your email address will not be published. Required fields are marked *

*