I came accross a post of Matthew Weier about exactly the same problem:
http://www.mail-archive.com/[email protected]/msg16674.html
What I wish to do is currently impossible due to a lack in the dispatch
process.
Maybe I'll move my code in an ActionHelper.




debussy007 wrote:
> 
> Hey,
> 
> When throwing the exception it seems that the request will still be
> executed and then additionally the errorController will be executed.
> 
> Is something like this 
> throw new My_Exception_AccessDenied('Access Denied.');
> not sufficient from the preDispatch() ?
> 
> 
> 
> 
> 
> Jurian Sluiman wrote:
>> 
>> Op Monday 24 August 2009 01:13:36 schreef debussy007:
>>> Hi,
>>>
>>> I have a plugin checking in the preDispatch() method if the user (role)
>>> may
>>> have access to the requested resource.
>>> If not, I will display an error message 'Access Denied'.
>>> I detect if the request was Ajax, in this case, I'll have to send the
>>> message through Json:
>>>
>>>
>>> if($this->_request->isXmlHttpRequest()) {
>>>     echo Zend_Json::encode( array('success' => false, 'msg' => 'Access
>>> denied.') );
>>>     die();
>>> }
>>>
>>> If I don't use die(), the request will continue its way and go to some
>>> method, probably displaying also Json. But the access should be denied
>>> and
>>> nothing should be printed afterwards.
>>>
>>> Is die() a good way of doing this or is there a more proper way ?
>>>
>>> Thank you !!
>> 
>> If you throw an Zend_Controller_Action_Exception you get a 404: not
>> found. If 
>> you throw some other exceptions, you get a 500: server error. I extended
>> the 
>> error plugin by recognizing My_Acl_Exception. It will return a 403:
>> Forbidden 
>> error.
>> 
>> Your error controller might have a AJAX context switch for all AJAX calls
>> (and 
>> such: might be able to return 404's and 500's as well).
>> 
>> Regards, Jurian
>> --
>> Jurian Sluiman
>> Soflomo.com
>> 
>> 
>>  
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Proper-way-to-stop-a-request-from-preDispatch---tp25108403p25130770.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to