Created
May 5, 2011 17:37
-
-
Save nissuk/957482 to your computer and use it in GitHub Desktop.
CakePHP 1.3: paginationで検索条件を引き継ぐ例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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