Skip to content

Instantly share code, notes, and snippets.

@nissuk
Created May 5, 2011 17:37
Show Gist options
  • Save nissuk/957482 to your computer and use it in GitHub Desktop.
Save nissuk/957482 to your computer and use it in GitHub Desktop.
CakePHP 1.3: paginationで検索条件を引き継ぐ例
<?php
class UsersController extends AppController {
var $name = 'Users';
// 1. ページネーションの既定の設定を行います。
var $paginate = array(
'limit' => 10,
// optionsを設定してoptions['limit']を設定しないと
// viewで$this->Paginator->counter()したときに
// Noticeエラーが出たり%end%が正しく計算されないので
// あらかじめ設定しておきます。
'options' => array(
'limit' => 10
)
);
function index() {
// 2. $_GETから必要なパラメータ(この例では性別(gender))を取得します。
$params = array();
if (isset($_GET['gender'])) $params['gender'] = $_GET['gender'];
// 3. 引き継がせる検索条件を['options']['?']に、
// データベースの検索条件を['conditions']に
// それぞれ設定します。
if ($params) {
$this->paginate['options']['?'] = $params;
$this->paginate['conditions'] = $params;
}
$this->User->recursive = 0;
// 4. データを取得、設定します。
$this->set('users', $this->paginate());
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment