我有以下cakephp查询:
$this->request->data = $this->AnsMatrixLubrication->find('all', array(
'conditions' => array('eq_model' => $eq_model)
));
输出如下:
Array (
[0] => Array (
[AnsMatrixLubrication] => Array (
[id] => 228
[matrix_lubrication_id] => 1
[eq_model] => D11 R
[A] => x
[B] => x
[C] => x
[D] => x
[E] => x
[F] => x
[G] => x
[H] => x
[created] => 2014-08-15 20:40:06
[modified] => 2014-08-15 20:40:06
)
)
[1] => Array (
[AnsMatrixLubrication] => Array (
[id] => 229
[matrix_lubrication_id] => 2
[eq_model] => D11 R
[A] => y
[B] => y
[C] => y
[D] => y
[E] => y
[F] => y
[G] => y
[H] => y
[created] => 2014-08-15 20:40:06
[modified] => 2014-08-15 20:40:06
)
)
)
但是我需要Cake命名约定的输出,我的意思是[Model][0][field_name]
。
为什么find
方法不显示CakePHP命名约定的输出?如果它应该是默认行为,我该如何解决?
编辑
CakePHP版本:2.4.6
是期望的格式
如文档中所示,这是find all调用的预期返回格式:
调用find('all')的结果将是以下形式:
Array
(
[0] => Array
(
[ModelName] => Array
(
[id] => 83
[field1] => value1
[field2] => value2
[field3] => value3
)
[AssociatedModelName] => Array
(
[id] => 1
[field1] => value1
[field2] => value2
[field3] => value3
)
)
)
表单字段和查找调用不是一回事
你所链接到的文档用于表单字段的命名约定(强调添加):
如果你需要指定多个字段使用相同的字段名,从而创建一个数组,可以保存一次saveAll(),使用以下约定:
echo $this->Form->input('Modelname.0.fieldname');
echo $this->Form->input('Modelname.1.fieldname');
这没有引用find-all返回的数据结构(尽管如果例如在Post hasMany Comment上进行了查找-注释数据将是您当前期望的格式)。
下面的链接解决了我的问题。
http://nuts-and-bolts-of-cakephp.com/2008/10/27/editing-multiple-records-with-saveall/使用Set::combine()
函数,我可以将find('all')
输出转换为字段约定。
非常感谢你的帮助