views:

178

answers:

3

Hi Folks,

how do you handle middle sized projects with PHP and Zend Framework. Do you use Zend DB Table / Row for your Models and Database operations ? Or do you have some kind of Abstract Model class with your SQL Statements ?

I would like to hear some opinions, thanks.

+4  A: 

I'd recommend Zend_Db_Table and Row for basic handling of database stuff. It's not very advanced (see Doctrine for a full ORM) but is a good way to encapsulate functionality and you can add custom functionality to Row objects.

You can always add raw SQL methods to your models:

   class MyModel extends Zend_Db_Table_Abstract {

        public function getSomething(){
            return $this->getAdapter()->fetchAll("SELECT * FROM `tbl`");
        }

    }
David Caunt
+1; this is basically what my answer said. In past projects where I used ZF, we derived classes from Zend_Db_Table_Abstract for each of our tables; it worked rather well, and allowed us to have a class hierarchy supporting common capabilities between some types of tables (lookup tables, for example).
James McNellis
@James: Do you extend only Zend_Db_Table Abstract or altough Zend_Db_Table_Row?
ArneRie
We only extended Zend_Db_Table_Abstract; we probably could have saved ourselves a bit of work by extending Zend_Db_Table_Row too, though. We ended up with two layers of models--the concrete table classes, and a second application layer model that utilized those table classes.
James McNellis
+1  A: 

We personally use Zend_Db_Select() in models in our company. It's because we use many joins and stuff in our ecommerce software. For simple apps is Zend_Db_Table suitable.

Tomáš Fejfar
+1  A: 

I've been using Doctrine lately for the DB layer and haven't looked back. I found it simple to populate object graphs from the DB. Other solutions were too cumbersome in dealing with relationships for my liking.

My domain model sits above the DB layer and manages the business logic.

It really depends on your domain model though. The current version of Doctrine requires all models to extend a class, so it's not suitable if you need model inheritance. Also, it's only suitable if your model is similar to your DB structure.

Richard Nguyen