2012-01-12 16 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

相關問題