I'm currently building a new ZF based app, and on the advice of many
articles I've read, and my own opinion, want to separate the "model"
classes from the DB access classes. My problem is, for all the articles
advising this is the way to do it, I've yet to find an example
implementation or any advice on how to implement it in the real world
with ZF.
As far as I understand it, the DB layer should be hidden under the model
layer, so at no point should the controller be accessing the Table or
Row classes.
For example, say I have these classes:
User - This is the user object
User_Table extends Zend_Db_Table
User_Table_Row extends Zend_Db_Table_Row
So, say we're in a controller and have some data for a new user,
creating that user would be a case of:
$user = new User($properties);
But what about looking up an existing user? Which of these is right?:
$user = new User($id);
$user = User::find($id);
$users = new Users();
$user = $users->find($id);
And getting a collection of multiple users? I want an array of User
objects returned, not User_Table_Row objects, where should these come
from and how should they be created internally by the model.
Sorry for all the questions, I just really want to do this the best way,
Thanks,
--
Jack
没有评论:
发表评论