Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-20-2008, 10:04 PM
Junior Member
 
Join Date: Jan 2008
Posts: 4
Thumbs up default error controller never gets called

I am trying to use Zend_Controller_Plugin_ErrorHandler to handle all 404 and 500 errors. But so far, I don't even think my error controller is getting called at all. The index controller for me default module and another test module both work fine any way I call them in the URL. But I don't think my error controller ever gets called at all unless I specify it directly. For example, if I request /default/error/error, my error controller gets called and I see the error page I would expect. But if I go to /doesnotexist, then $frontController->dispatch () throws an "invalid controller specified" exception. The examples of how to do this all look very simple. I copied them, but it does not work. Here is what I am doing.

In my bootstrap:
$frontController = Zend_Controller_Front::getInstance ();
$frontController->setControllerDirectory (array (
"default" => $appDir."/default/controllers",
"professional" => $appDir."/module2/controllers"));
$frontController->setDefaultModule ("default");
$frontController->registerPlugin (new Zend_Controller_Plugin_ErrorHandler ());
$frontController->returnResponse (true);
$frontController->throwExceptions (true);

In /default/controllers/ErrorController.php:
(as far as I can tell, this controller never gets called when I request on invalid controller)
class ErrorController extends Zend_Controller_Action
{
protected $_view = null;
protected $_registry = null;

public function init ()
{
parent::init ();

$this->_helper->removeHelper ('viewRenderer');

$this->_view = $this->getInvokeArg ("view");
$this->_registry = Zend_Registry::getInstance ();
}

public function errorAction ()
{
$this->getResponse ()->setRawHeader ('HTTP/1.1 404 Not Found');
$this->_view->setScriptPath ($appDir."/default/views/scripts");
$this->getResponse ()->setBody ($this->_view->render ("error.phtml"));

// I never tested this because ZF never calls this function.
/*
$error = $this->_getParam ('error_handler');
switch ($error->type)
{
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ ACTION:
// 404 error -- controller or action not found
$this->getResponse ()->setRawHeader ('HTTP/1.1 404 Not Found');
$this->_view->setScriptPath ($this->_registry ['appDir']."/default/views/scripts");
$this->_response->setBody ($this->_view->render ("error.phtml"));
break;
default:
$this->getResponse ()->setRawHeader ('HTTP/1.1 404 Not Found');
$this->_view->setScriptPath ($this->_registry ['appDir']."/default/views/scripts");
$this->_response->setBody ($this->_view->render ("error.phtml"));
}
*/
}

public function __call ($name, $parameters)
{
$this->_redirect ('/');
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 04:41 AM
Junior Member
 
Join Date: Apr 2008
Posts: 1
Default Exactly

Exactly, I've been struggling with the same problem for ages and guess what no one gives two shits about the issue!

I've tried almost every single trick in the book (manual) and various forum tips but nothing seems to work.

One thought was that this could be because I am not using a modular directory structure, so I created a module called 'default'. But that too obviously did not work

Quiety frankly dude.. am over it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-02-2008, 02:02 PM
Junior Member
 
Join Date: May 2008
Posts: 4
Default

try to change "throwExeptions" in your bootstrap:
$frontController->throwExceptions ( false );

I also don't have modular directory structure (like -> zuhair)

I removed also:
$frontController->setParam ( 'useDefaultControllerAlways', true );

in my case it's working when I call:
http://.../no_existing_controller/
and
http://.../no_existing_controller/no_existing_action/

but when I hit
http://.../existing_controller/no_existing_action

nothing is happening, and I dunno why...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-02-2008, 03:34 PM
Junior Member
 
Join Date: Apr 2008
Posts: 8
Default

you should set throwExceptions to false, that should fix it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-02-2008, 04:14 PM
Junior Member
 
Join Date: May 2008
Posts: 4
Default

I said it before ;-)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:22 AM.