0
尝试POST到API时出现以下错误。我已经遵循this这本书的教程,所以我不确定为什么插入不起作用。CakePHP - CRUD API:插入到数据库CakePHP时出错
Message: Call to member function error() on boolean
Trace: ControllerTrait.php
我的添加功能是通过烘烤,但尽管如此,错误似乎发生在实体保存过程中。
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组件尚未加载。 – AD7six