2010年2月17日星期三

Re: [fw-mvc] Exceptions handling in front controller plugins

Can you paste the production part of the ini file specific to the
frontController? Are there other modules? Does the Default/ directory
act as a module or it is pointed to by controllerDirectory?

Also, what version of ZF? I think we've seen a related problem in
1.10.0, but not sure yet.

-ralph

Cristian Bichis wrote:
> Hi,
>
> I was noticing that if i throw an error into a front controller plugin
> the actual error is displayed instead of the error page from
> /Default/Error/Error action...
>
> I got this setup for exceptions:
> resources.frontcontroller.throwexceptions = false
>
> *I was throwing the error on:*
>
> public function preDispatch(Zend_Controller_Request_Abstract $request) {
> ....
> throw new App_Exception_Acl('no rights', 404);
> .....
> }
> *
> The error controller:*
>
> class ErrorController extends Zend_Controller_Action
> {
> public function errorAction()
> {
> $errors = $this->_getParam('error_handler');
>
> switch ($errors->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()->setHttpResponseCode(404);
> $this->view->message = 'Page not found';
> break;
> default:
> // application error
> $this->getResponse()->setHttpResponseCode(500);
> $this->view->message = 'Application error';
> break;
> }
>
> $this->view->exception = $errors->exception;
> $this->view->request = $errors->request;
> }
> }
>
>
> *The error.phtml:*
>
> <h1>An error occurred</h1>
> <p>An error occurred; please try again later.</p>
> <?php
> if( isset($this->exception) && (APPLICATION_ENV == 'development') )
> echo $this->exception->getMessage() . "\n" .
> $this->exception->getTraceAsString();
>
>
> Any idea why is not actually rendered the error.phtml but instead the
> error directly ?
>
> --
> Best regards,
> Cristian Bichis
> www.zftutorials.com | www.zfforums.com | www.zftalk.com | www.zflinks.com
>

没有评论: