Technology and Development
Introducing Codeigniter
This is my first post about Codeigniter, a free MVC PHP framework that is very easy to understand and implement. I have been using Codeigniter for quite a while now and is very please with what I’ve achieved.
Hold on, what is MVC?
MVC is short for Model View Controller and is an abstract way of separating the logic, display and controlling decision. I wouldn’t go through defining them but for the sake of simplicity, I’ll throw in a simple example. And also, I’ll go through this example in Codeigniter’s way of talking, so that we won’t go to outer space without knowing it
Model is where the information is. View is how the information will be presented. Controller is which information to choose.
For example we want to view a page with the id of 3. we will have the controller called “view_page” and pass it an argument id = 3. The controller will then grab the information (page detail) by calling the “page” model and ask for page detail with the id of 3. After retrieving the page detail from the model, the controller would then call the “display_page” view and give it what to display.
In detail:
The Controller’s code will be:
1 2 3 4 5 | $id=$_GET['id']; $data=$this->page_model->loadpage($id); $this->load->view('page-display', $data); |
The Model’s code will be:
1 2 3 4 5 6 7 8 9 | function loadpage($id) { $data = db->query('SELECT * FROM page WHERE id=$id'); return $data; } |
The View’s code will be:
1 | echo $data['content']; |
If that’s not understandable, please, dig in to the framework and see what’s in there. Also, Codeigniter offered a 20 minutes video tutorial (oh, I love theses!) to quickly setup codeigniter and have a blog running in less than half an hour. Pretty impressive to me.
If you’d ever run into a wall, the user guide is always there to help you.
Have fun igniting codes
| Print article | This entry was posted by dekarvn on October 10, 2009 at 6:49 pm, and is filed under PHP/MySQL. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |