How my Zend_Db_Table models look like

I am not too happy with the ZF Frameworks Table access solution. Not that I have anything against the Table Gateway pattern, but in most web applications you almost always have to join data some way or another. Even this rather simple application, a blog, needs joins for displaying articles so that category, comment count and tags can be displayed. Therefore I use an instance of Zend_Db_Table_Abstract only for the simplest purposes and pimp it by using lots of public methods and Zend_Db_Select. An example:

class SomeModel extends Zend_Db_Table_Abstract
  $_name = "someTable";
  $_primary = "id";

  public function getSomethingByJoin($param1, $param2)
     $db = $this->getAdapter();
     $select = $db->select();
     ...[build select]
     $result = $db->query($select);

     return $result;

That way you still follow the MVC pattern and don’t have to take one compromise after another for getting the Table Gateway to reproduce a result that looks like a join.

More about: ZendFramework

Sign up for my newsletter to get notified when I post new content on this blog and with the occasional exclusive content only for subscribers.

By clicking on the Subscribe button I am giving my consent for Benjamin Eberlei to hold my name and email address for the purposes of contacting me with a newsletter on the topics of this blog. You can unsubscribe with one click at any time and withdraw your consent. No spam. I will never share your e-mail address. Privacy Policy