- 2009年4月 9日 01:04
- Technical

CakePHPでGETでパラメータを渡してActionを呼び出す場合、名前付きかそうでないかのパラメータでControllerでのパラメータの受け取り方法が違う。
まぁ公式サイトのドキュメントにも書いてあるのだけどね。
名前付きのパラメータ :: Routesの設定 :: 環境設定 :: CakePHPによる開発 :: マニュアル :: 1.2 Collection :: The Cookbook
パラメータ名を付けない場合はコントローラの関数の引数に順にセットされるけど、パラメータ付きの場合は関数の引数ではなく、$this->passedArgs[”]を使え、と。
URL: /donations/view/recent/2001
Mapping: DonationsController->view('recent', '2001');
URL: /contents/view/chapter:models/section:associations
Mapping: ContentsController->view();
$this->passedArgs['chapter'] = 'models';
$this->passedArgs['section'] = 'associations';
これに気づかずに、しばらく値が受け取れなくて悩んでしまった。普通にHTMLヘルパーで
$html->link("リンク", array("action"=>"detail", "asin"=>$item['ASIN']));
なんてやると、普通に名前付きパラメータになるしね。
- Newer: 会社レビューサイト "Review360"
- Older: 会社が苦しいときに出てくる"実態"
Comments:0
Trackbacks:0
- TrackBack URL for this entry
- http://www.swingingblue.net/mt/mt-tb.cgi/2012
- Listed below are links to weblogs that reference
- CakePHPで名前付きパラメータを受け取る from きままな日記帳