CakePHP コントローラーから別のテーブルを参照して表示する。(ページャー機能付き)

現在クラウドソーシング一括検索サイトを構築中の浅尾です。

ベースはもちろんCakePHP

そこで少しハマったので忘備録として残しておきます。

AtestsController.phpからBtestsテーブルを見に行く方法(ページネーション付き)

//AtestsController.phpの内容
<?phpclass AestsController extends AppController { public $paginate = array( 'limit' => 20, 'sort'=>'created', 'direction'=>'desc', 'paramType' => 'querystring', //'order' => array( // 'Task.created' => 'desc' //) ); public function index() { $this -> set('data', $this->paginate('Btest'));}

次にindex.ctp

<table class="table table-striped table-hover"><?php foreach ($data as $btest){?>
<?php debug($btest); ?>
<?php endforeach; ?>?><?php }?></table><div ><ul class="pagination"> <?php echo $this->Paginator->prev(__('prev'), array('tag' => 'li'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a')); ?> <?php echo $this->Paginator->numbers(array('separator' => '','currentTag' => 'a', 'currentClass' => 'active','tag' => 'li','first' => 1, 'ellipsis' => '<li class="disabled"><a>...</a></li>')); ?> <?php echo $this->Paginator->next(__('next'), array('tag' => 'li','currentClass' => 'disabled'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a')); ?> </ul></div>

コレで動くはずです。

セキュリティ上、変数の名前など色々変更していますので不具合があればご連絡下さい。