The model
Now let's code the core part.
What our model will do:
Our model will do all CRUD model actions, insert, update, delete, get and object, return a collection of objects, etc.
The model receives the information from the controller, information can come as single parameters or as complete objects.
The code
1 <?php 2 class categories_model extends crud_model { 3 protected $daotype = 'categories_DAO'; 4 } 5 ?>
And.. that's it...
If you want you can read more about the model, or just jump to the DAO and VO page
Does the model need to inherit / extend crud_model?
No, if your application is simple and the model represents a single table, follow this approach.
If your application is complex, Create your classes, use the DAO's and VO's to pass and store information and then create a class to interact with your model. Give the name of that one to your controller!
I need extra functionality, where can I add?
Need a non provided function: just add as public
Need to modify an existing: overload (also just add copying the signature from the parent)
Can I use my existing model?
Absolutely, you can also take any open source code and drop it anywhere.
Just remember the only rule for your classes to be found is : class name == filename.
What's in the model
The model is a class or set of classes where:
All business rules are located
All DB processing is made
All info manipulation, transformation is done
Having a good model results into robust applications and helps avoiding code repetition
What's NOT in the model
Contain any reference to user submitted information
Contain global variables that make application difficult to maintain
Presentation layer instructions, echo
Contain any HTML code
Contain any messages, language entries