CakePHP的virtualField发现都不为null [英] CakePHP virtualField find all not null

查看:167
本文介绍了CakePHP的virtualField发现都不为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库表transactions,它有一个字段account。我想从当前数据集中检索所有非空帐户行的子集,并将其作为virtualField,我可以在我的视图中访问该行。

I have a database table "transactions" which has a field "account". I want to retrieve a subset of all not-null account rows from the current set of data and have it as a virtualField I can access down the line in my view.

class Transaction extends AppModel {
    public $virtualFields = array(
        "Accounts" => $this->Transaction->find("all", array("conditions" => array("not" => array("Transaction.account" => null))))
    );
}

这样我得到一个数组, Accounts。

So that I get an array of all transactions with non-null account fields named "Accounts".

这不工作 - 给我意外的T_VARIABLE错误(不喜欢$ this)。我试图遵循此处指南。我是一个中等水平的PHP开发人员,这是我第一个真正的蛋糕项目,所以我可能会出现这个完全错误。

This doesn't work - gives me "unexpected T_VARIABLE" error (doesn't like $this). I was trying to follow the guide here. I'm a moderate level PHP developer and this is my first real Cake project, so I may be going about this completely wrong.

推荐答案

当您在查询的模型中时,不要模型名称:

When you're inside the model that you're querying, you don't specify the model name, just:

$this->find('all'); // when you're inside transaction model

...所以试试这个:

...so try this:

"Accounts" => $this->find("all", array("conditions" => array("not" => array("Transaction.account" => null))))

这篇关于CakePHP的virtualField发现都不为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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