The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Zend Framework and Model

Messing around with the Zend Framework and just wondering how everyone is handleing the model when it comes to the mvc part of the framework. This is what i have so far. Not new to OOP but still have some way to go. Any insight would be greatly appreciated.

I removed the view (html) from this as well as the comments to save space since its pretty straight forward at this stage and the main goal i hope to accomplish is get input on how people are passing the model into the controller.

Two points
1. Consider passing $db into the constructor. This removes the dependency on Zend::registry and allows for using multiple databases should the need arise. Not as big of a hassle as you might think.

2. Unless you have a bunch more functionality in your Users class then just extend Zend_Db_Table and go on from there.

I extend Zend_Db_Table for the "fetching" side. The trouble is that Zend_Db_Table returns its results as Zend_Db_Rowsets that you could really do with overriding for the rest of the specific stuff you need.

I extend Zend_Db_Table for the "fetching" side. The trouble is that Zend_Db_Table returns its results as Zend_Db_Rowsets that you could really do with overriding for the rest of the specific stuff you need.

Allowing one to specify the class for return rows and row sets has been asked for a long time ago. It's easy to extend Zend_Db_Table to allow:

As for this example this is just an example app to see how zf works. Thank you for pointing out Zend_Db_Table as i have yet to take a real in depth look at this class.

Right now the main goal is to get the basic outlining architecture of the framework. This is where the question of how to pass the model to the controller comes from. I have seen a lot of "tutorials" do everything inside the controller methods including the IBM/Zend tutorial which I find odd they would place that much code in one class.

Is an include and an instance of the model (passing in $db to constructor) the best way to get to the model from inside the controller?

If your controller needs a view from another directory (not the one specified in your FrontController) you can add it in the __contruct() method on per-controller basis. ZF is smart enough to first look in the last added directory, and if it doesnt find the view file there it keeps looking at other directorys you might have added during the script execution.