2016-11-14 1 views
-1

Cakephp 3.xに新しいですが、データセットのページを設定しようとしていますが、表示されている、下のナビゲーションバーも表示されており、うまく動作していると思います。ページネーションはページネイターヘルパーとページネーションを使用しているにもかかわらず、すべての結果を表示します。

以下は私のコントローラです。

public $paginate = ['limit' => 2,'order' => ['sample.posts' => 'asc']]; 

public function initialize() 
{ 
    parent::initialize(); 
    $this->layout = 'frontend'; 
    $this->loadComponent('Paginator'); 
    $this->loadComponent('Flash'); // Include the FlashComponent 
} 

public function index() 
{ 
    $this->set('Posts', $this->paginate()); 
    $posts = $this->Posts->find('all'); 
    $this->set(compact('posts')); 
} 

これは私のテンプレートファイルです。

<table> 
     <tr>paginate 
      <th><?php echo $this->Paginator->sort('ID', 'id'); ?></th> 
      <th><?php echo $this->Paginator->sort('Title', 'title'); ?></th> 
     </tr> 
      <?php foreach($posts as $post): ?> 
     <tr> 
      <td><?php echo $post['id'] ?> </td> 
      <td><?php echo $post['title'] ?> </td> 
     </tr> 
    <?php endforeach; ?> 
</table> 

<?php echo $this->Paginator->numbers(); ?> 
<?php echo $this->Paginator->prev('« Previous', array('class' => 'disabled')); ?> 
<?php echo $this->Paginator->next('Next »', array('class' => 'disabled')); ?> 
<?php echo $this->Paginator->counter(); ?> 

すべてのヘルプは本当にありがとうございます。

答えて

1

あなたのインデックス関数はページ設定機能を持っている必要があり、$ postsをパラメータとして渡すべきです。

 public function index() 
     { 
      $posts = $this->Posts->find('all'); 
      $posts = $this->paginate($posts); 
      $this->set(compact('posts')); 
     } 
関連する問題