📜  cakephp 404 异常 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:51.333000             🧑  作者: Mango

代码示例1
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']);
}