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