備忘録

個人的な試行錯誤のメモですので間違った情報が載っていたらごめんなさい。

CakePHP3(3.0.0-alpha1)のブログチュートリアルで記事一覧にページネーションを追加してみる

CakePHP3(3.0.0-alpha1)のブログチュートリアルで記事一覧にページネーションを追加してみる

①ArticlesControllerに下記を追加

public $helpers = ['Paginator'];
public $components = ['Paginator'];
public $paginate = ['limit' => '5', 'order' => ['Article.id' => 'asc']];


②ArticlesControllerのindexアクションを変更

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

③index.ctpに下記を追加

<?php echo $this->Paginator->prev('<<' . __('previous')); ?>
<?php echo $this->Paginator->numbers(['modulus' => 9]); ?>
<?php echo $this->Paginator->next(__('next') . '>>'); ?>

デフォルトだとリストタグが付いてくるっぽい。