2015-04-16 33 views
2

我們如何處理在CakePHP? 例如自定義錯誤,如果最終用戶直接修改URL,我們如何處理cakePHP中的自定義錯誤?

如:http://localhost/cake/topics/view/6

的情況下,如果該值沒有,我們怎麼能處理這種類型的情況。 代碼

if (!$this->Topic->exists($id)) 
 
\t \t { 
 
\t \t \t //$this->cakeError('fatal_error'); 
 
\t \t \t //$this->fatal_error('Invalid topic'); 
 
\t \t \t //throw new NotFoundException(__('Invalid topic')); 
 
\t \t \t throw new NotFoundException(('Could not find that post')); 
 
\t \t } 
 
\t \t 
 
\t \t $options = array('conditions' => array('Topic.' . $this->Topic->primaryKey => $id)); 
 
\t \t $this->set('topic', $this->Topic->find('first', $options));

只寫

throw new NotFoundException(('Could not find that post'));

這是不好的,似乎。 那麼我們該如何處理呢?

請幫我

+0

重定向到一個404頁不要扔東西的用戶沒有是做什麼的想法的錯誤是壞的UX – madalinivascu

回答