我试图在我的cns_controller.php文件的index()方法中检索数据库中记录的id。我想将它用于find()。但是,$ this-> Cn-> id没有返回值,因此find()也不起作用。
$uses = array('Cn', 'Release');
/*check non-null value in released_user_id,
showing Release tab has been signed off*/
$releaseSignedOff = $this->Release->find('all', array(
'conditions' => array('Release.cn_id =' => $this->Cn->id,
'Release.released_user_id !=' => null)
));
(sizeof($releaseSignedOff) > 0) ? $releaseSignedOff = true : $releaseSignedOff = false;
$this->set('releaseSignedOff', $releaseSignedOff);
有什么想法吗?
由于
答案 0 :(得分:0)
我最终没有使用我的index
视图,而是在cns
数据库表中查找最新记录,并使用返回值作为参数重定向到view
视图:
if (!$id) {
$most_recent_change_note = $this->Cn->find('first', array(
'order' => array('Cn.id DESC')
));
$this->redirect(array('controller' => 'cns',
'action' => 'view/'.$most_recent_change_note['Cn']['id']));
}
对于分页,我最终使用了CakePHP的$neighbors
功能:
function get_neighbors($id) {
$neighbors = $this->Cn->find('neighbors', array('field' => 'id',
'value' => $id));
$this->set('neighbors', $neighbors);
}
然后在我的view
视图中,我使用这些值来创建链接:
<div class="paging">
<?php echo ($neighbors['next']) ? $html->link('<< Prev',
array('controller'=>'cns',
'action'=>'view/'.$neighbors['next']['Cn']['id'])).' | ' : '<< Prev | ';
echo $html->link('Next >>', array('controller'=>'cns',
'action'=>'view/'.$neighbors['prev']['Cn']['id'])); ?>
</div>
感谢Charles和Ross帮助我得出这个结论。 :)