2012-01-12 12 views
0

私は2つのモデルがセクションモデルと結びついています(ギャラリー、記事)、これをセクション/ view.ctp.soにページングしたいのですが、私は2つの問題があります
1 - $ paginate私はパースエラーを取得するセクション$ idで記事を検索すること 2 - どのように..ビューファイルに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のクラスプロパティ宣言で変数またはロジックを使用することはできません。 1つは、とにかくそこには$id変数の範囲がありません。

ページネーションクエリに条件を渡すには、あなたがあなたのpaginate()呼び出しに2番目の引数として、それを追加する必要があります。

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

あなたはCakePHPのと、同じページに取り組んで改ページの2つのインスタンスを取得するために苦労していますURLに「page:2」を受け取ったときにページングしているデータのセットを知ることはできません。両方のデータをページングするだけです。 Here is an article outline a possible hack

関連する問題