CakePHP virtualField find all not null

橙三吉。 提交于 2019-12-12 01:07:00

问题


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

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

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.


回答1:


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


来源:https://stackoverflow.com/questions/20458331/cakephp-virtualfield-find-all-not-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!