2009年1月30日星期五

Re: [fw-mvc] Separating Models from DB Access

Yeah its a big problem! The/a data mapper is used to create a clean
"Domain Model" which is really for modelling very complex business
requirements, which can be overkill for many projects, however I am
glad that there are proposals now for the tools to allow this :)

Me and Rob Allen have discussed some ideas on our blogs.

http://akrabat.com/2008/12/13/on-models-in-a-zend-framework-application

http://www.thepopeisdead.com/main/comments/zend_framework_book_example_application/

Hope this helps

2009/1/30 Bryce Lohr <brycel@patientadvocate.org>:
> You're running into the classic object-relational mapping problem. It's a
> terribly difficult problem in general, which is why you don't commonly see
> solutions in those articles. They're primarily selling the ideals, and
> leaving the implementation as an exercise for the reader... :)
>
> Check out Benjamin Eberlei's proposal [1] for a Data Mapper for ZF, and
> Martin Fowler's PoEAA for background info.
>
> [1] http://framework.zend.com/wiki/x/OwCQ
>
> Regards,
> Bryce Lohr
>
>
> Jack Sleight wrote:
>>
>> Hi,
>> 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,
>
>

--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------

没有评论: