Zend DB Table ? Or SQL by your own?
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 he开发者_运维技巧ar some opinions, thanks.
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`");
}
}
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.
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.
精彩评论