我有2个数据库表,
1. gallery -> id, title, description
2. gallery_images -> image_id, gallery_id, name, image_title, thumb_name, image_name
我可以使用我的 Admin_Model_GalleryImages 为特定的 gallery_id 选择图像,我的结果数组如下所示 -
Array (
[0] => Array (
[image_id] => 1
[gallery_id] => 24
[image_title] => NICEIC.png
[thumb_name] => thumb_.6386527349.png
[image_name] => 6386527349.png )
[1] => Array (
[image_id] => 2
[gallery_id] => 24
[image_title] => gas_safe_logo_monoblack.png
[thumb_name] => thumb_2100528832.png
[image_name] => 2100528832.png )
图库模型中的代码:
require_once 'Zend/Db/Table/Abstract.php';
require_once APPLICATION_PATH . '/modules/admin/models/Gallery.php';
class Admin_Model_GalleryImages extends Zend_Db_Table_Abstract {
protected $_name = 'gallery_images';
protected $_referenceMap = array(
'Gallery' => array(
'columns' => array('gallery_id'),
'refTableClass' => 'Admin_Model_Gallery',
'refColumns' => array('id'),
'onDelete' => self::CASCADE,
'onUpdate' =>self::RESTRICT
)
);
public function getImages($id){
$galleryImages = new self();
$galleryRowset = $galleryImages->select();
$galleryRowset->where('gallery_id='.$id);
$images = $galleryImages->fetchAll($galleryRowset);
return $images;
控制器中的 listimages 操作:
public function listimagesAction(){
$id = $this->_getParam('id');
$currentImages = Admin_Model_GalleryImages::getImages($id);
if ($currentImages->count() > 0) {
$this->view->galleryImages = $currentImages;
} else {
$this->view->galleriesImages = null;
}
}
但我想要第一个表的结果以及第二个表的结果,如下所示:
Array (
[0] => Array (
[image_id] => 1
[gallery_id] => 24
[image_title] => NICEIC.png
[thumb_name] => thumb_.6386527349.png
[image_name] => 6386527349.png
[id] => 24
[title] => Somename
[description] => description )
我尝试使用findDependentRowset但无法正常工作。请让我知道如何实现这一目标。任何帮助深表感谢。