我有两个模型绑定了剖面模型这两个模型称为(图库,文章),我想在部分/ view.ctp.so中对所有这些进行分页我有两个问题
1 - 当在$ paginate中放入$ id来按部分检索文章时我会得到解析错误
2 - 如何在视图文件中分隔两个分页(图库,文章)..
var $paginate = array(
'Article'=>array(
'limit' => 1,
'page' => 1,
parse error here//
'conditions' => array('section_id'=>$id)
),
'Gallery'=>array(
'limit' => 3,
'page' => 1,
'conditions' => array('section_id'=>86))
)
;
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid gallery', true));
$this->redirect(array('action' => 'index'));
}
$gallery = $this->paginate('Gallery');
// find Articles at sections
$articles = $this->paginate('Article');
$section = $this->Section->findById($id);
// set the section for the view
$this->set(compact('articles','gallery','section'));
}
段/视图
<div class="related">
<table>
<tbody>
<h3> section is <?php echo $section ['Section']['name']; ?></h3>
<br />
<?php foreach($articles as $article): ?>
<tr>
<td><?php if($article['Article']['status']== 1){echo $article['Article']['title'];} ?></td>
<td><?php if($article['Article']['status']== 1){echo ' '.$html->link('View', '/articles/view/'.$article['Article']['id']);}?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php if($section['Section']['id']==86): ?>
<div class="related">
<table>
<tbody>
<?php foreach($gallery as $galler): ?>
<tr>
<td> <?php echo ' '.$html->link($galler['Gallery']['name'], '/galleries/view/'.$galler['Gallery']['id']);?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
));
?> </p>
<div class="paging">
<?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>
| <?php echo $this->Paginator->numbers();?>
|
<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
</div>
<?php endif ; ?>
答案 0 :(得分:2)
您不能在PHP中的类属性声明中使用变量或逻辑。首先,无论如何都没有$id
变量的范围。
要将条件传递给分页查询,您需要将其作为第二个参数添加到paginate()
调用中:
$articles = $this->paginate('Article', array('Article.section_id' => $id));
你很难在同一个页面上运行两个分页实例,因为当它在URL中收到“page:2”时,CakePHP将不知道你正在分页的数据集,我认为它只会分页数据集。 Here is an article outline a possible hack