Reading deeper into your question where a url is purposely mistyped and you
want to throw an exception you can create a simple plugin that executes
before the controller is dispatched like so.
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if
(!Zend_Controller_Front::getInstance()->getDispatcher()->isDispatchable($thi
s->getRequest())) {
$request->setControllerName('index')->setActionName('index')->setDispatched(
false);
Throw new Exception('The url you requested cannot be found.')
}
}
Tom Shaw
[email protected]
-----Original Message-----
From: Tom Shaw [mailto:[email protected]]
Sent: Wednesday, April 29, 2009 10:53 PM
To: 'prado'; [email protected]
Subject: RE: [fw-general] extending ErrorController beyond controller and
action to get vars
The below controller already handles all errors for example in your
controller throw a test exception, once an exception is caught the
controller will dispatch you to the below ErrorController/errorAction. To
get errors for missing post/get variables just do a control structure check
for the variables in your controller and if they do not exist throw an
exception.
If(empty($variable)) {
Throw new Exception('Missing post/get variable.') }
Tom Shaw
[email protected]
-----Original Message-----
From: prado [mailto:[email protected]]
Sent: Wednesday, April 29, 2009 9:16 PM
To: [email protected]
Subject: [fw-general] extending ErrorController beyond controller and action
to get vars
Hi
how can i extend below this simple ErrorController beyond controller-action
to GET variables for eg. $this->getRequest()->getParam('id')
i need to get errors for individual content items too, where an invalid id
or not found/wrong id variables are purposely typed on the browser
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:
$this->getResponse()->setRawHeader('HTTP/1.1 404 Not
Found');
$this->view->errorType = 404;
$this->view->exception = $errors->exception;
break;
default:
throw $errors->exception;
break;
}
}
}
Any help would be greatly appreciated
cheers
--
View this message in context:
http://www.nabble.com/extending-ErrorController-beyond-controller-and-action
-to-get-vars-tp23306135p23306135.html
Sent from the Zend Framework mailing list archive at Nabble.com.