【发布时间】:2015-04-16 05:49:36
【问题描述】:
我们如何处理 cakePHP 中的自定义错误? 例如,如果最终用户直接修改 URL,
例如:http://localhost/cake/topics/view/6
如果这个值不可用,我们该如何处理这种情况。 代码
if (!$this->Topic->exists($id))
{
//$this->cakeError('fatal_error');
//$this->fatal_error('Invalid topic');
//throw new NotFoundException(__('Invalid topic'));
throw new NotFoundException(('Could not find that post'));
}
$options = array('conditions' => array('Topic.' . $this->Topic->primaryKey => $id));
$this->set('topic', $this->Topic->find('first', $options));
随便写
throw new NotFoundException(('Could not find that post'));
看起来不太好。 那么我们该如何处理呢?
请帮帮我
【问题讨论】:
-
重定向到 404 页面不要抛出用户不知道这样做对用户体验不利的错误