CakePHP 2.0.4-使用条件的findBy魔术方法 [英] CakePHP 2.0.4 - findBy magic methods with conditions

查看:68
本文介绍了CakePHP 2.0.4-使用条件的findBy魔术方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图构建一个小的cms来测试CakePHP 2.x

I am trying to build a small cms to test CakePHP 2.x

在我的PagesController(用于显示单个站点)中,我使用以下代码:

In my PagesController (for displaying single sites), I use this code:

$page = $this->Page->findByNavtitle($name, array(
    'conditions' => array(
        'Page.visible' => '1',
        ),
    )
);

仅当记录被标记为可见时才设置结果。
但是此代码块会引发错误。

The result should only set when the record is marked as visible. But this codeblock throws an error.

API描述,在这些findBy魔术方法中只允许一个参数。

The API describes, that just one parameter is allowed in these findBy magic methods.

如何获得带条件的结果?

How can I get the result with conditions?

推荐答案

您不能在 findBy中添加条件方法。而是使用查找

You cannot add conditions to findBy method. Instead use find:



$page = $this->Page->find('first', array(
  'conditions' => array(
    'Page.nav_title'     => $name,
    'Page.visible' => 1
  )
));

希望有帮助

这篇关于CakePHP 2.0.4-使用条件的findBy魔术方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆