I’d like to use the same class as a row class and a base class for getting results, but think I am doing it the wrong way…
Ie I need the same class to extend Zend_Db_Table_Row_Abstract and Zend_Db_Table_Abstract but think this is putting logic for two different things into the same class? (and extending two is impossible)..
For example, I think the base class should handle select queries etc, and the row class should handle updating etc. But I’d like to be able to go:
class Article extends BaseModel { //Set table name and some custom functions }
BaseModel { //Define custom functions for finding rows and updating }
Article::findAll() //This is table logic
Article::insert($data); //This is row login
What’s the right way of doing this?
I think you are looking for the ActiveRecord pattern:
There is a proposal for a
Zend_Db_ActiveRecordcomponent, but it never left the “New” stage. There is a number of UseCases in the proposal though, which might give you some ideas how to implement that yourself. You might also be interested in using existing 3rd party solutions, like Propel or phpactiverecordPlease be aware that ActiveRecord is often misused and has a number of drawbacks due to the violation of separation of concerns due to the intermingling of db access and business logic in one class.