【发布时间】:2016-06-09 19:44:19
【问题描述】:
我在尝试 POST 到 API 时收到以下错误。我已经按照本书的this 教程进行操作,所以我不确定为什么插入不起作用。
Message: Call to member function error() on boolean
Trace: ControllerTrait.php
我的 add 函数是通过 bake 制作的,但尽管如此,在保存实体期间似乎发生了错误。
public function add()
{
$author = $this->Authors->newEntity();
if ($this->request->is('post')) {
$author = $this->Authors->patchEntity($author, $this->request->data);
if ($this->Authors->save($author)) {
$this->Flash->success(__('The author has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The author could not be saved. Please, try again.'));
}
}
$this->set(compact('author'));
$this->set('_serialize', ['author']);
}
【问题讨论】:
-
错误信息本身只是因为没有加载flash组件。