Some typical model layer in Zend Framework

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
sk0rp
Forum Newbie
Posts: 2
Joined: Thu May 24, 2007 7:59 am

Some typical model layer in Zend Framework

Post by sk0rp »

My future application needs to manage tests and task like Moodle module Quiz plus some user management.
I assume that all work with DB table will be set up in one class. For example all select, update and delete queries will be set up in UserTable like class.

In the first place I was thinking about something like this: http://rudy.mif.pg.gda.pl/~skorp/stuff/ss.png
where all queries for table 'users' where set up in User_Manager class. User_Manager can factor User which is contener for users table's row. User::__construct() and User::update() metods use User_Manager class to deal with DB.

Later I found that all metods in Manager classes can be just static metods in factored classes.
Simply: User::drop(), User::findByCol().
But there is a problem with Zend_Db_Table_Abstract because all desirable metods are unfortunately not static.

The question is: what's the best choice?
a) choose first (featured by diagram) model
b) overwrite Zend_Db_Table_Abstract making all needed static metods (a lot of work!)
c) make something different (what?)
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

The User_Manager description sounds like an implementation of a Data Mapper (a good way of doing this). I would avoid static usage unless it's either absolutely necessary or only used in a handful of locations. It's a good way to couple classes half way to hell.

I would dig into the Data Mapper some more. If Zend_Db is proving to be a long drawn out process then don't be afraid to just use something else.
sk0rp
Forum Newbie
Posts: 2
Joined: Thu May 24, 2007 7:59 am

Post by sk0rp »

Data Mapper pattern is exactly what I need!
Thank you
Post Reply