如何在CakePHP中使用命名参数查询模型?
-
03-07-2019 - |
题
url: /contents/view/chapter:models/section:associations
class ContentsController extends AppController {
function view() {
$this->params['named'];
}
}
例如,我有上面的url和controller,目标是使用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