Cakephp:can Model-> find('all')返回没有模型名的结果 [英] Cakephp: can Model->find('all') return results without model name
问题描述
使用Model-> find('all')返回具有以下结构的数组:
Using Model->find('all') returns an array with the following structure:
array(
0 => array('Model1' => array(/* Model1 fields*/), 'Model2' => array(/* Model2 fields*/), ...),
1 => array('Model1' => array(/* Model1 fields*/), 'Model2' => array(/* Model2 fields*/), ...),
...)
当查询单个模型时(即Recursive = -1),是否可以返回结果作为具有以下结构的数组:
When a single Model is queried (i.e. Recursive = -1), is it possible to have the results returned as an array with the following structure:
array(0 => /* Model1 fields*/, 1 => /* Model1 fields*/, etc...)
我以为我读这个地方,不能弄清楚如何做到这一点,或者如果可能的话。
I thought I read this somewhere a while back but cannot figure out how to do this or if it is possible.
推荐答案
您还可以修改该模型的aftersave方法,以便在执行查询后返回$ data ['Modelname']。本质上,它基本上是一个数组移位,你只有$ arrayname ['fieldname'],而不是$ arrayname ['模型'] ['fieldname']。这是你在问什么?
You could also modify that model's aftersave method so that it returns $data['Modelname'] after it performs the query... In essence, it'd basically be an array shift and you would only have $arrayname['fieldname'] rather than $arrayname['Model']['fieldname']. Is that what you were asking?
这篇关于Cakephp:can Model-> find('all')返回没有模型名的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!