Model view controller 在视图上从数据库调用图像超出MVC?

Model view controller 在视图上从数据库调用图像超出MVC?,model-view-controller,zend-framework,design-patterns,Model View Controller,Zend Framework,Design Patterns,我已经为基表创建了一个模型,即带有infos的模型。 然后是图像表的另一个模型,并将其扩展到我的通用图像模型,如下所示: class Application_Model_GenericImages extends Zend_Db_Table_Abstract { public function getImage($relCol, $id) { $db = $this->getDefaultAdapter(); return $db->fetchRow("SE

我已经为基表创建了一个模型,即带有infos的模型。 然后是图像表的另一个模型,并将其扩展到我的通用图像模型,如下所示:

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}'");
   }

}
$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();
图像表的模型如下所示:

class Application_Model_ImagesTable extends Application_Model_GenericImages {
   protected $_name = 'images_table';
}
然后在控制器上执行以下操作:

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}'");
   }

}
$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);
}

这是错的吗?如果是的话,这有多糟糕?正确的方法是什么?

这个问题毫无意义。您的代码有很多错误(包括可能的SQL注入)。此外,您不应该使用
Zend\u Db\u Table\u Abstract
作为模型层结构的基础。模型不是数据库抽象。