CakePHP Archive
[CakePHP] Pagination + Search ページ遷移時に検索条件を維持させる
- 2010-10-11 (月)
- CakePHP
CakeのPagenateについて。バージョンは1.3。
Pagenate使ってるときにconditionsを使うと、自動生成されるナビゲーションにはその条件が反映されない。
1ページ目は検索条件通り出てるのに2ページ目に進むとクリアされる現象が起きる。
その事についてはかなり既出のようだ。
検索条件を維持したままページ遷移するにはPagenateにクエリを渡さなければならない。
view/posts/index.ctp
$category_label はfind('list')で得たカテゴリーのidとラベルが入っているものとする。
(カテゴリーの選択は1記事あたりに1つのみってことで)
これで送信するとPostsControllerのindexメソッドで$this->data['search']として受け取る事が出来る。
controller/posts_controller.php
-
'limit' => 25,
-
'Post.id' => 'asc'
-
)
-
);
-
function index()
-
{
-
$this->paginate['conditions']['category'] = $this->data['search']['category'];
-
}
-
$this->paginate['conditions']['category'] = $this->passedArgs['category'];
-
}
-
$this->set('posts',$this->paginate('Post'));
-
}
Pagenateの設定の仕方は殆どfind()と同じらしい。
$this->passedArgsに配列形式でクエリを渡せばページ移動しても検索状態が維持出来る。
渡す値は一応Sanitizeしといた方がいい気がする。
-
App::import('Sanitize');
-
Sanitize::clean($this->data['search']['category']);
- Comments: 0
- Trackbacks: 0
[CakePHP] PagenatorのURLをGETな感じに変更したい
- 2010-10-10 (日)
- CakePHP
CakePHPのPagenationの便利さに感動したのも束の間、URL見て我が目を疑う。
http://example.com/news/page:3/sort:id/direction:asc
なにこれ!(゚Д゚lll) なんでコロン!?
世のCake使いのみなさんはこのURL気持ち悪くないんだろうか?
普通にアンバサンドとイコールで繋げてあるやつがいいんだけど…
http://example.com/news/?page=3&sort=id&direction=asc
検索しても根本的な解決方法が見つからないまま朝日を拝む始末…(今6時)
試しに後者のURLを打ち込んでみたら同じ動作になったから、
アンバサンドとイコールのURLでもソートやページングは機能するらしかった。
なら変更も出来るのじゃないかと検索していたら、変更した場合の問題についてのレスが見つかる。
- Comments: 0
- Trackbacks: 0
-
- そしてこのSQLはわれながらよく書いたと思う 2010-11-15
- CSVの列っていう方がいいのかな…118項目だった 2010-11-15
- 楽天のCSVの項目が116個もあった衝撃 2010-11-15
- オフィスで香水臭振りまくのは迷惑だと知れ 2010-11-15
- ぐあー フレグランステロやー 2010-11-15
- More updates...
Powered by Twitter Tools
-
- ホームページビルダー
- 擬似クラス
- 楽天
- 1Column
- 2BOX
- 2ch
- 2column
- 2Helvs
- 3column
- 5BOX
- Actionscript
- Ajax
- Animation
- AntiSpam
- API
- apple
- Aptana
- Aqua
- ASCII
- Assets
- AutoExternalLink
- background
- backup
- BETA
- Blog Status
- breadcrumb
- Bubble
- bug
- Button
- calendar
- Calendarizm
- canvas
- Center
- Chain
- Chrome
- Class
- Click Event
- CMS
- ColorMeShopPro
- ContactForm
- Control
- Cookie
- CSS
- CSS3
- CSV
- Custom
- date()
- Demo
- Dojo
- Download
- Dreamweaver
- dropdown
- Dummy Text
- Effect
- Elastic
- Error
- Filter
- filter.html
- FireFox
- Fixed
- Flash
- Floating
- foglio
- Form
- free material
- free script
- Function Reference
- Fx.Morph
- Fx.Scroll
- Fx.Slide
- Fx.Tween
- gettext
- get_posts
- GMarker
- Go-To-Top
- GoogleChart
- GoogleEarth
- GoogleMap
- GoogleSearch
- Hack
- Halves
- Highlight
- Horizontal
- HTML&XHTML
- HTML5
- HTML5API
- Icon
- IE
- illustrator
- infowindow
- iphone
- Javascript
- jQuery
- jQuery.plugin
- KML
- LeftMenu
- liquid
- ListMenu
- Localization
- login-system
- Magpie RSS
- Mobile
- mooFollow
- MooTools
- mooTyping
- number format()
- OnlineGame
- OOP
- OpenPNE
- Pagenation
- permalink
- Photoshop
- PHP
- ping
- plugin
- poedit
- Polyline
- prototype.js
- Regular Expression
- RightMenu
- rollover
- RPC
- RSS
- Safari
- Sample
- script.aculo.us
- scrollbar
- selection
- selectors
- SEO
- session
- Shortcode
- Sidebar Widgets
- slimbbs
- Smarty
- SmoothScroll
- strtotime()
- Symphony-CMS
- Tableless
- Tab Menu
- Tar
- Template
- Template Engine
- Template Tags
- time()
- TinyMCE
- token
- Tooltip
- Transparent
- Tutorial
- Tutoriarl
- Valid
- Validator
- vertical-align
- Web Browser
- Web Site
- Wiki
- window.open
- wordpress
- wp-custom
- wp-function
- wp-plugin
- wp-themes
- xampp
- XHTML
- XML
- YUI
- Zend Framework
- Zend_Form
- Zend_View
- zeromail