2012-01-12 53 views
0

我有两个模型绑定与节模型这两个模型叫(画廊,文章),我想分页/ view.ctp.so这一切所有这一切我有两个问题
1 - 当$美元放在$ paginate来检索部分的$ id文章中,我得到解析错误 2,如何查看文件两个paginations(图库,文章)之间分开..

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 '&nbsp;'.$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 '&nbsp;'.$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 ; ?> 

回答

2

您不能在PHP中的类属性声明中使用变量或逻辑。首先,无论如何,这个$id变量的范围是没有的。

要通过条件分页查询,你需要把它作为第二个参数添加到您的paginate()电话:

$articles = $this->paginate('Article', array('Article.section_id' => $id)); 

你将很难得到在同一页上工作分页的两个实例,作为CakePHP的当它在URL中收到“page:2”时不会知道您要分页的哪组数据,我认为它只会分页处理这两组数据。 Here is an article outline a possible hack