Zend Quickstart Tutorial Conceptual Problem
I am trying to learn zend framework, and managed to get through the whole quickstart tutorial they have. However, there is something that I simply can not understand, and was hoping somebody can help me with.
In the tutorial, you create a db-table class, a mapper, and a model. I read the documentation, and understand the purpose of the db-table class (define table, relations, create/fetch rows). When you query the db-table class, you'll get an object of class db-table-row, which you can use to manipulate a specific record in the db.
However, I can not understand why the tutorial would have me create a mapper and a model, nor the reason for defining getter/setter methods in the model (shouldn't those be provided by db-table-row?)
Even in the controller, they created an object from the model class and the mapper class, then they completely igno开发者_运维知识库red the model object, and just used the mapper object.
Is there any need at all to have those 3 classes? what different purpose does each fulfill? As far as I can see, all I need is the db-table class, am I right?
When you query the db-table class, you'll get an object of class db-table-row
No you get db-table-rowset instead which is collection of row . secondly
you don't even need db-table class
$dbTable = new Zend_Db_Table('tableName');
But since db-table class allow you to define relationship between other tables inside it (business logic) hence became important .
db-table-row became important when the entity is important for e.g User Table . Inside your custom db-table-row for user you can add method getTopics();
which return rowset for all the topics created by theat user hence fruther helping with business logic.
精彩评论