7月
17
2010
[CakePHP] あいまい検索とpaginatのURLパラメータとか
投稿者: admin, カテゴリ: CakePHP, tags: CakePHP, controller, Sort投稿日: 2010.07.17 - 09:56
更新日: 2011.09.18 - 01:09
前回、検索を簡単にできるけれどあいまい検索ができないという結果になった。
pc.casey.jp » CakePHPの検索機能 :
http://pc.casey.jp/archives/2289
単純に検索するだけなら簡単に実装できるが、検索結果を paginate で sort させると検索文字が消えてしまう。これは paginate が生成する URL に検索文字が含まれないためだ。 paginate に値を渡す方法はいくつも掲載されていたがどういうわけかうまく行かなかった。そこで、改めて避けては通れないだろう検索機能について調べてみた。いろいろな実装方法があるだろうし、美しいとは相変わらず言えないが参考程度に。
スポンサードリンク
controller
$q = isset($this->params['url']['Keyword'])? $this->params['url']['Keyword'] : null;
// $q = isset($this->data['Item']['Keyword']) ? $this->data['Item']['Keyword'] : null;
$this->layout = 'item_search';
$this->Item->recursive = 0;
$this->set('q', $q);
$this->set('items', $this->paginate(array(
'Item.group_id ='=> $this->Auth->user('group_id'),
'Item.name LIKE' => '%' . $q . '%',
)));
view
<tr>
<th><?php echo $this->Paginator->sort('id', null,array('url'=>array('?'=>array('Keyword'=>$q))));?></th>
<th><?php echo $this->Paginator->sort('name', null,array('url'=>array('?'=>array('Keyword'=>$q))));?></th>
<th><?php echo $this->Paginator->sort('item_group_id',null,array('url'=>array('?'=>array('Keyword'=>$q))));?></th>
<th><?php __('Actions');?></th>
</tr>
※CakePHP 1.3.2
関連記事
- CakePHP – ACL再入門(3)
- CakePHP – ACL再入門(4)
- CakePHP pagenatorのメモ
- [CakePHP] ログをデータベースに記録する
- [CakePHP] 検索機能
- [CakePHP] RSSを取得する(2)表示
- [CakePHP] テストアプリケーションのブログを構築 – test_apps_posts
スポンサードリンク

エントリ (RSS)