CakePHPで名前付きパラメーターを使用してモデルをクエリするにはどうすればよいですか?
-
03-07-2019 - |
質問
url: /contents/view/chapter:models/section:associations
class ContentsController extends AppController {
function view() {
$this->params['named'];
}
}
たとえば、上記のURLとコントローラーがあり、目的はURLのキー/値情報を使用してデータベースを照会することです。これを行うにはどうすればモデルを作成できますか?
解決
passedArgs配列を使用する必要があります:
url:/ contents / view / chapter:models / section:associations
class ContentsController extends AppController {
function view() {
$foo = $this->Foo->find(
array('chapter'=>$this->passedArgs['chapter'],
'section'=>$this->passedArgs['section']));
}
}
これは、Cake 1.2の一部として、または次の追加で利用可能です:
所属していません StackOverflow