我有一个beforeSave-callback,每当我创建一个新的实体时,它都会被调用。然而,当我编辑的时候,它根本不会被调用。在文档中找不到任何可能有帮助的内容。
下面是我的编辑函数:
public function edit($id = null) {
if (!$id) {
throw new NotFoundException(__('Invalid article'));
}
$article = $this->Articles->get($id);
if ($this->request->is(['post', 'put'])) {
$this->Articles->patchEntity($article, $this->request->data);
if ($this->Articles->save($article)) {
$this->Flash->success(__('Your article has been updated.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Unable to update your article.'));
}
$this->set('article', $article);
} https://stackoverflow.com/questions/29663990
复制相似问题