Question : cakephp 404 exception
Answered by : stormy-sloth-kpt3du0djzg1
use Cake\Http\Exception\NotFoundException;
public function view($id = null)
{ $article = $this->Articles->findById($id)->first(); if (empty($article)) { throw new NotFoundException(__('Article not found')); } $this->set('article', $article); $this->viewBuilder()->setOption('serialize', ['article']);
}
Source : https://book.cakephp.org/4/en/development/errors.html | Last Update : Fri, 31 Dec 21