Using JOIN within the Zend Framework

I found documentation very sparse on the subject of using JOIN with the Zend Framework. So i set out on a quest of many hours figuring out how to get it to work. Here is what I ended up with.

I do not claim that this is the best way to do it, or that it is correct, but here is how I solved this and got JOIN working within Zend Framework.


class Asset extends Zend_Db_Table 
    private $dbAdapter;
    public function __construct()
        $this->dbAdapter= Zend_Registry::get('dbAdapter');

    public function getAssetInfo()
        $select = new Zend_Db_Select($this->dbAdapter);

        $select->from(array('a' => 'asset'), '*');
        $select->join(array('al' => 'asset_locations'), 
                            ' = a.asset_locations_id');
	$select->join(array('ac' => 'asset_categories'), 
                            ' = a.asset_categories_id');
	$select->where('a.statuses_id <> 5');
	$stmt = $select->query();
	$result = $stmt->fetchAll();
	return $result;

public function indexAction()
    // instantiate the classes, with Zend_Db_Table		
    $allAssetInfo = new Asset();

    $this->view->allAssetInfo = $allAssetInfo->getAssetInfo();

allAssetInfo as $asset) : ?>
escape($asset['asset_categories_name']); ?> escape($asset['city']); ?> escape($asset['asset_name']); ?>

3 responses to “Using JOIN within the Zend Framework”