我为基表创建了一个模型,一个带有信息的模型。 然后是图像表的另一个模型,并将其扩展到我的通用图像模型,其中包括:
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}'");
}
}
图像表的模型如下:
class Application_Model_ImagesTable extends Application_Model_GenericImages {
protected $_name = 'images_table';
}
然后在控制器上执行以下操作:
$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();
最后在观点上就像是:
foreach ($infoTable->fetchAll() as $info) {
//Print Some Info
$image = $this->imageModel->getImage('info_id', $info->id);
}
这是错的吗?如果是的话,这有多糟糕,怎么做正确的方法呢?