在cakephp中动态添加虚拟字段 [英] Dynamically add virtual field in cakephp
问题描述
我使用CakePHP 2.1.3;我想在控制器中动态创建一个虚拟字段。是否可以?
问题是,当我试图在表中找到最大值,它给我从模型数组中的另一个数组。
I am using CakePHP 2.1.3; I want to create a virtual field dynamically in a controller. Is it possible? The problem is when I am trying to find max value in a table it gives me another array from the model array. Please ask if you need more information.
当我尝试执行以下查询时,
When I am trying to execute the following query,
$find_max_case_count = $this->CaseMaster->find('first', array(
'conditions' => array(
'CaseMaster.CLIENT_ID' => $client_id,
'CaseMaster.CASE_NO LIKE' => '%-%'
),
'fields' => array('max(CaseMaster.CASE_NO) AS MAX_NO')
));
它给我一个数组:
[0]=> array([MAX_NO]=> 52)
但我希望它像: p>
However I want it to be like as:
[CaseMaster] => array([MAX_NO] => 52)
推荐答案
I找到了解决方案。我可以在运行时创建虚拟字段。代码应如下所示:
I found a solution. I can make the virtual field at runtime. The code should looks like:
$this->CaseMaster->virtualFields['MAX_NO'] = 0;
将它写在查询查询的上方,查询将保持原样。
此链接很有用找出解决方案。
Write it just above the find query and the query will remain same as it was written. This link was helpful to find out the solution.
这篇关于在cakephp中动态添加虚拟字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!