【发布时间】:2016-04-11 13:42:16
【问题描述】:
我有一个在 Cakephp2 中显示相关产品的网格,它工作得很好,但是正在查看的相同产品显示在相关产品的网格中,我该如何排除它?
这是我的艺术品控制器代码:
public function view($id = null) {
if (!$this->Artwork->exists($id)) {
throw new NotFoundException(__('Invalid artwork'));
}
$options = array('conditions' => array(
'Artwork.' . $this->Artwork->primaryKey => $id),
'recursive' => 0);
$artwork = $this->Artwork->find('first', $options);
$this->set('artwork', $artwork);
// related artworks
$status = 'Artwork.status';
$id = 'Artwork.artist_id';
$related = $this->Artwork->find('all',
array(
'limit' => 4,
'conditions' => array(
$status => 1,
$id => $artwork['Artwork']['artist_id'])));
$this->set('artworks', $related);
}
【问题讨论】:
标签: php cakephp cakephp-2.0 has-and-belongs-to-many