NYCPHP Meetup

NYPHP.org

[zendframework] a modeling question

Michael Hernandez mhernandez at techally.com
Tue Jun 2 12:23:55 EDT 2009


On Tue, 2009-06-02 at 12:09 -0400, David Mintz wrote:
> 
> 
> On Tue, Jun 2, 2009 at 11:46 AM, Michael Hernandez
> <mhernandez at techally.com> wrote:
>         
>         On Tue, 2009-06-02 at 11:36 -0400, David Mintz wrote:
>         > At
>         >
>         http://framework.zend.com/docs/quickstart/create-a-model-and-database-table you see they use a DataMapper class to map the domain object to the database. My question is, if you are totally certain that the back end you will be using will be a database (indeed, a MySQL database) now and forever, do you really need that extra layer?
>         >
>         > --
>         > David Mintz
>         > http://davidmintz.org/
>         >
>         > The subtle source is clear and bright
>         > The tributary streams flow through the darkness
>         
>         
>         I found the extra layer to prove useful when I realized that
>         my User
>         model needed to make use of multiple tables. I was able to
>         update my
>         model to use multiple table objects when necessary. If you
>         were going to
>         write all the SQL yourself instead of using the methods that
>         Zend_Db_Table provides, I guess it wouldn't matter as much?
>         
> 
> Well, I would ask, is it a crime to have some SQL in your model class
> -- again, assuming you're comfortable committing yourself to a db for
> persistence? Also, we can make use of Zend_Db_Table's (and ..._Row)'s
> higher-level methods (find(), save()) and keep the raw SQL to a
> minimim, possibly zero.
> 
> 

I don't think it's a crime, but for me I think if I'm going to use the
framework, I'm going to try to use the framework's features wherever
possible, so I try to use Zend_Db_Table objects and so on, instead of
writing the SQL myself. Of course there are going to be times you need
to write your own SQL because not every case can be covered by the
framework, and luckily ZF makes it pretty easy for you in those cases.

For the most part though, even for joins, you can accomplish things via
the framework's built in classes or extend those classes.  If you begin
writing your own SQL for everything you might end up with an application
that is half ZF and half "DIY F" (the F is for framework, I swear). Now
that isn't necessarily a crime either, but one of the benefits of using
a framework at all is that it leaves easy maintenance possibilities for
anyone that is familiar with the framework you use, so if you end up
going off the deep end you might lose that benefit.

--Mike H




More information about the zendframework mailing list