【发布时间】:2020-04-13 23:14:02
【问题描述】:
当我删除一个实体时,cakephp 会警告该请求未应用授权检查。当我返回上一个操作时,实体被删除。不知何故,它是通过绕过 authorization 中间件来实现的。 附言 我正在使用作曲家的骨架应用程序。我没有对删除操作应用授权。我预计删除会失败,但它仍然存在。
CakePHP 4
控制器代码。
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$product = $this->Products->get($id);
if ($this->Products->delete($product)) {
$this->Flash->success(__('The product has been deleted.'));
} else {
$this->Flash->error(__('The product could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
【问题讨论】:
-
请分享您的控制器代码。
-
@AmanRawat 添加了控制器代码。
标签: cakephp authorization middleware