CakePHP 2.0.4 - findBy 带有条件的魔术方法

发布于 2024-12-24 21:38:54 字数 354 浏览 5 评论 0原文

我正在尝试构建一个小型cms来测试CakePHP 2.x

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

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

仅当记录标记为可见时才设置结果。 但是这个代码块会抛出一个错误。

API 描述了这些 findBy 魔术方法中只允许使用一个参数。

怎样才能得到有条件的结果呢?

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

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.

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

How can I get the result with conditions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄荷梦 2024-12-31 21:38:54

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


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

希望有帮助

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
  )
));

Hope it helps

書生途 2024-12-31 21:38:54

$this->Model->findAllBy(string $value, array $fields, array $order, int $limit, int $page, int $recursive);

$this->Model->findAllBy(string $value, array $fields, array $order, int $limit, int $page, int $recursive);

撧情箌佬 2024-12-31 21:38:54

Findbyid 在 cake php 中

$result = $this->Modelname->findById($id, array('Alpha.name'));

,其中 $id 是您正在搜索的记录的 id,Alpha.name 是您需要的字段(例如来自模型 Alpha 的名称)

Findbyid in cake php

$result = $this->Modelname->findById($id, array('Alpha.name'));

where $id is an id of record you're searching for and Alpha.name is a field you need (e.g. name from model Alpha)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文