Extending the Models in Zend Framework = Better readability + Easier to maintain

Posted on: Mar 03, 2009 by wenbert

Let’s say I have a Model named: Psdump.php and it is found in /models/Psdump.php

< ?php
 
/**
 * Psdump.php
 * /opt/apache2/htdocs/apps/org_v2/application/models/Psdump.php
 */
 
require_once APPLICATION_PATH.'/models/PsdumpTable.php'; //I will need this
 
class Psdump extends Zend_Db_Table
{
    protected $_table;    public function getTable()
    {
        if(null === $this->_table) {
            $this->_table = new PsdumpTable;
        }
        return $this->_table;
    }
 
	public function fetchAllEmployees()
	{
		return $this->getTable()->fetchActiveEmployees();
	}
 
}

And for the “extension”…

&lt; ?php
 
/**
 * PsdumpTable
 * /opt/apache2/htdocs/apps/org_v2/application/models/PsdumpTable.php
 *
 */
 
class PsdumpTable extends Zend_Db_Table_Abstract
{
    protected $_name = 'psdump';    public function insert(array $data)
    {
        return parent::insert($data);
    }
 
	public function fetchActiveEmployees()
	{
		$sql = "SELECT * FROM ".$this->_name." WHERE Status=".$this->_db->quote('A');
		return $this->_db->fetchAll($sql);
	}
}

Even though I will have more files — the end result is that this Model setup will be easier to maintain and understand.

Hehe, another post that only I can understand :P


Subscribe to comments Comment | Trackback |
Post Tags: , ,

Browse Timeline


Add a Comment


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">


© Copyright 2007 eKini Web Developer Blog . Thanks for visiting!