When does the Model come into play?
Posted: Fri Nov 19, 2010 12:59 pm
Yesterday, I went through the 20 minute tutorial on CodeIgniter's site(http://codeigniter.com/tutorials/watch/blog/), which details how to create a very simple blog using CI.
It's my understanding that the model is the data layer of the program, but I'm not really sure what exactly that means. The tutorial video that I posted does not use a model at all - just a single controller and a single view. The blog worked just fine, so I am a little confused as to the purpose of the model.
If I were writing an application with CodeIgniter(or any MVC framework), what sort of code would I be likely to place in the model? Database queries? Processing of data?
Further expanding on my question: Let's say, for the sake of example, I'm writing a calculator that, for some reason, requires an MVC framework. Would I process the calculations in the model?
Let's say that someone visits the site, would this be the "correct" chain of events?
1. Calculator_Controller calls Calculator_View, which presents a form.
2. The user enters 1+1.
3. Calculator_View submits the form back to Calculator_Controller.
4. Calculator_Controller sends the input to Calculator_Model to process.
5. Calculator_Model adds the numbers and sends them back to Calculator_Controller.
6. Calculator_Controller sends the solution to Calculator_View, which presents it to the user.
Thanks in advance for any insight that you can offer!
It's my understanding that the model is the data layer of the program, but I'm not really sure what exactly that means. The tutorial video that I posted does not use a model at all - just a single controller and a single view. The blog worked just fine, so I am a little confused as to the purpose of the model.
If I were writing an application with CodeIgniter(or any MVC framework), what sort of code would I be likely to place in the model? Database queries? Processing of data?
Further expanding on my question: Let's say, for the sake of example, I'm writing a calculator that, for some reason, requires an MVC framework. Would I process the calculations in the model?
Let's say that someone visits the site, would this be the "correct" chain of events?
1. Calculator_Controller calls Calculator_View, which presents a form.
2. The user enters 1+1.
3. Calculator_View submits the form back to Calculator_Controller.
4. Calculator_Controller sends the input to Calculator_Model to process.
5. Calculator_Model adds the numbers and sends them back to Calculator_Controller.
6. Calculator_Controller sends the solution to Calculator_View, which presents it to the user.
Thanks in advance for any insight that you can offer!