How do I query a model using named parameters in CakePHP?
-
03-07-2019 - |
Question
url: /contents/view/chapter:models/section:associations
class ContentsController extends AppController {
function view() {
$this->params['named'];
}
}
For example, I have the url and controller above and the goal is to use the key/value information from the url to query a database. How would I create a model to do this?
Solution
You need to use the passedArgs array:
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']));
}
}
This is available as a part of Cake 1.2, or with the following additions:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow