我正在尝试构建一个小cms来测试CakePHP 2.x
在我的PagesController(用于显示单个站点)中,我使用以下代码:$page = $this->Page->findByNavtitle($name, array(
'conditions' => array(
'Page.visible' => '1',
),
)
);
结果应该只在记录被标记为可见时设置。但是这个代码块抛出一个错误。
API描述,在这些findBy魔术方法中只允许一个参数。
如何获得带条件的结果?
findBy方法不能添加条件。使用查找:
<>之前
$page = $this->Page->find('first', array(
'conditions' => array(
'Page.nav_title' => $name,
'Page.visible' => 1
)
));
之前希望有所帮助
$this->Model->findAllBy(string $value, array $fields, array $order, int $limit, int $page, int $recursive);
Findbyid in cake php
$result = $this->Modelname->findById($id, array('Alpha.name'));
其中$id是您正在搜索的记录的id, Alpha.name是您需要的字段(例如,name from model Alpha)