【问题标题】:How can we handle custom errors in cakePHP?我们如何处理 cakePHP 中的自定义错误?
【发布时间】: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 页面不要抛出用户不知道这样做对用户体验不利的错误

标签: php jquery cakephp


【解决方案1】:

将其重定向到 404 页面的更好方法。

您可以通过CakePHP 2.0 - How to make custom error pages?的问题的答案来做到这一点

【讨论】:

    猜你喜欢
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    • 2019-10-19
    • 2018-10-12
    • 2019-12-07
    相关资源
    最近更新 更多