LoginSignup
1
0

More than 1 year has passed since last update.

cakephp3.9でペジネーション【コントローラーのみで】

Last updated at Posted at 2021-06-30

備忘録です。

Controllerにて

TopController
        public $paginate = [
//limitiの値は任意で変更してください。
            'limit' => 12
        ];

あとはいつも通り取得

TopControllerのメソッド内
                //テーブル
                $postes = TableRegistry::getTableLocator()->get('postes');
                $dataes = $postes->find('all')
                ->where(['del_flg' => 0,
                'composition LIKE' => $whereSerch]);

                //取ってきた情報をここで引数にして渡す。
                $dataes = $this->paginate($dataes);

                $this->set(compact('dataes'));

viewにて

以下のようにすれば超えていてれば勝手に出てくるし、超えて無ければ出てこない。
簡単実装だね。

view.ctp
    <ul class="pagination">
        <li>
            <?php 
                if ($this->Paginator->hasPrev()) {  
                    echo $this->Paginator->prev('< 前へ');
                }
            ?>
        </li>
            <?php 
             if (!empty($this->Paginator->hasPrev())){
                echo $this->Paginator->numbers();
             }
             ?>
        <li>
            <?php
                if ($this->Paginator->hasNext()) {  
                  echo $this->Paginator->next('次へ >');
                }
            ?>
        </li>
    </ul>

色んなフレームワークを触って仕事してるので忘れがち。
とりあえずメモとして保存ですよ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0