粉丝们,
我尝试在数据库中保存多个条目。
例子:
索引.ctp
echo $this->Form->create('Item');
echo $this->Form->input('0.Item.name');
echo $this->Form->input('1.Item.name');
echo $this->Form->end('save');
项目.php
class Item extends AppModel {
var $validate = array(
'name' => 'email'
);
}
项目控制器.php
public function index() {
if($this->request->is('post')){
if($this->Item->saveAll($this->request->data))
$this->Session->setFlash("saved successful");
else{
$this->Session->setFlash("saving error");
debug($this->Item->validationErrors);
}
}
}
当我尝试保存非电子邮件值时,我收到“保存错误”但输入字段没有消息。验证错误是:
array(
(int) 0 => array(
'name' => array(
(int) 0 => 'This field cannot be left blank'
)
),
(int) 1 => array(
'name' => array(
(int) 0 => 'This field cannot be left blank'
)
)
)
任何人都可以帮助我吗?
编辑:
调试 $this->request->data
array(
(int) 0 => array(
'Item' => array(
'name' => 'test'
)
),
(int) 1 => array(
'Item' => array(
'name' => 'test2'
)
)
)