首先,如果您要保存映射到同一模型的字段并想要多个数据库插入,则数据数组的格式应为 Mike 上面表示的格式:
即模型。{n}.field
您可以清楚地看到,他们明确表示,当您在同一模型中多次保存相同的字段名时,这是约定,因为手册部分的标题是名称“字段命名约定”
http://book.cakephp.org/view/1390/Automagic-Form-Elements#Field-naming-convention-1391
如果输入法不是为了让您以非预期的方式使用该方法而编写的,那么您不能真正将输入问题称为 CakePHP 错误。该方法在“。”上显式拆分传递的字符串。字符并假设如果您使用带有“。”的字符串。您打算格式化数据数组以使用 Model->save 或 Model->saveAll 保存的字符
其次,当我在最后测试您的代码时,它确实表现出一个合法的错误——它使用了我期望的数字索引,但重复了它们..
即 [0][0][Descriptor][title], 1 [Descriptor][title]
当我将索引移动到 save* 函数期望的位置时,解析是完美的。
即[描述符][0][标题],描述符[标题]
因此,如果您想使用助手,您应该按照它们的预期工作方式使用它们。如果您发明了自己的边缘案例,而该案例一开始并不打算由助手支持,这不是错误。
从您的示例来看-无论如何都没有理由不使用 saveAll 。你有什么避免它的理由吗?这似乎是做你所要求的正确方法。
** 编辑修复票http://cakephp.lighthouseapp.com/projects/42648/tickets/867 **
将此应用为 app/views/app_view.php
<?php
App::import('View', 'View', false);
class AppView extends View {
/**
* Constructor
*
* @param object $controller
*/
function __construct(&$controller){
parent::__construct($controller);
}
/**
* Temporary View::entity fix for 1.2.5
* Returns the entity reference of the current context as an array of identity parts
*
* @return array An array containing the identity elements of an entity
* @access public
*/
function entity() {
$assoc = ($this->association) ? $this->association : $this->model;
if (!empty($this->entityPath)) {
$path = explode('.', $this->entityPath);
$count = count($path);
if (
($count == 1 && !empty($this->association)) ||
($count == 1 && $this->model != $this->entityPath) ||
($count == 2 && !empty($this->fieldSuffix)) ||
is_numeric($path[0]) && !empty($assoc)
) {
array_unshift($path, $assoc);
}
return Set::filter($path);
}
return array_values(Set::filter(
array($assoc, $this->modelId, $this->field, $this->fieldSuffix)
));
}
}
?>
告诉您的控制器使用具有公共 $view 属性的视图。
<?php
class FooController extends Controller {
...
...
var $view = 'App';
...
...
}
?>