I've created a model for the base table, the one with the infos. Then another model for the images table, and extended it to my generic images model, which is the following:
class Application_Model_GenericImages extends Zend_Db_Table_Abstract {
public function getImage($relCol, $id) {
$db = $this->getDefaultAdapter();
return $db->fetchRow("SELECT * FROM {$_name}
WHERE {$_name}.{$relCol} = '{$id}'");
}
}
The model for the images table is like:
class Application_Model_ImagesTable extends Application_Model_GenericImages {
protected $_name = 'images_table';
}
Then on the controller i do the following:
$infoTable = $this->view->infoTable = new Application_Model_InfoTable();
/* I haven't made the info table here because there's no point to... */
$imagesModel = $this->view->imagesModel = new Application_Model_ImagesTable();
And finally on the view it's like:
foreach ($infoTable->fetchAll() as $info) {
//Print Some Info
$image = $this->imageModel->getImage('info_id', $info->id);
}
Is this wrong? If it is, how bad is this and how's the right way to do it?