#5850: Can't use custom methods in AppError when debug = 0
-------------------------+--------------------------------------------------
Reporter: msadouni | Type: Bug
Status: new | Priority: Medium
Milestone: 1.2.x.x | Component: Error Handling
Version: RC2 | Severity: Normal
Keywords: | Php_version: n/a
Cake_version: |
-------------------------+--------------------------------------------------
I'm trying to throw 403 errors when necessary.
I created a custom AppError class which extends ErrorHandler and contains
an 'error403' method, similar to the existing 'error404' :
{{{
function error403($params) {
extract($params, EXTR_OVERWRITE);
header("HTTP/1.0 403 Forbidden");
$this->controller->set(array(
'code' => '403',
'name' => 'Forbidden',
'message' => 'Forbidden',
'base' => $this->controller->base));
$this->__outputMessage('error403');
}
}}}
When the debug mode is set to anything else than 0, it works fine. When
it's set to 0, I get a 404 error instead.
Looking into the ErrorHandler constructor I noticed the following :
{{{
if ($method !== 'error') {
if (Configure::read() == 0){
$method = 'error404';
if(isset($code) && $code == 500) {
$method = 'error500';
}
}
}
}}}
Basically if the error received has a different name than 'error' it is
ignored and a 404 or 500 is thrown instead.
I got it to work by simply adding a test to check if the method called
exists :
{{{
if ($method !== 'error' && !method_exists($this, $method)) {
if (Configure::read() == 0){
$method = 'error404';
if(isset($code) && $code == 500) {
$method = 'error500';
}
}
}
}}}
It now works fine with debug = 0. I wasn't able to produce a test case
because it only works with debug = 0, which prevents the tests from
running and I'm not that familiar with core tests yet...
I attached a diff with the small change pasted above.
--
Ticket URL: <https://trac.cakephp.org/ticket/5850>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---