Cakephp 3.0 不保存实体,不 error/s... 发生了什么事?
Cakephp 3.0 not saving Entity, no error/s... what's going on?
$newContainer = $this->Containers->newEntity($this->request->data);
if($this->Containers->save($newContainer) !== false)
{
$this->Flash->success("Saved");
}
else
{
debug($newContainer);
}
总是显示调试,但没有验证错误。
调试输出:
object(Cake\ORM\Entity) {
'new' => true,
'accessible' => [
'*' => true
],
'properties' => [
'Container' => [
'name' => 'Test2',
'description' => 'test',
'slug' => '',
'thumbnail_image_url' => '',
'preview_video_image_url' => '',
'preview_video_url' => '',
'is_private' => '',
'index_weight' => '',
'custom_layout' => '',
'custom_view' => ''
]
],
'dirty' => [
'Container' => true
],
'original' => [],
'virtual' => [],
'errors' => [],
'repository' => 'Containers'
}
显然,数据库中实际上没有创建新记录...
有人知道发生了什么事吗?
在 cake 2.x 中,您可以使用 Model.field 名称作为表单输入,在 3.0 中这会导致问题并且不起作用,仅将字段名称用于表单输入。
$this->Form->input("Model.name"); // Wrong
$this->Form->input("name"); // Correct
$newContainer = $this->Containers->newEntity($this->request->data);
if($this->Containers->save($newContainer) !== false)
{
$this->Flash->success("Saved");
}
else
{
debug($newContainer);
}
总是显示调试,但没有验证错误。
调试输出:
object(Cake\ORM\Entity) {
'new' => true,
'accessible' => [
'*' => true
],
'properties' => [
'Container' => [
'name' => 'Test2',
'description' => 'test',
'slug' => '',
'thumbnail_image_url' => '',
'preview_video_image_url' => '',
'preview_video_url' => '',
'is_private' => '',
'index_weight' => '',
'custom_layout' => '',
'custom_view' => ''
]
],
'dirty' => [
'Container' => true
],
'original' => [],
'virtual' => [],
'errors' => [],
'repository' => 'Containers'
}
显然,数据库中实际上没有创建新记录...
有人知道发生了什么事吗?
在 cake 2.x 中,您可以使用 Model.field 名称作为表单输入,在 3.0 中这会导致问题并且不起作用,仅将字段名称用于表单输入。
$this->Form->input("Model.name"); // Wrong
$this->Form->input("name"); // Correct