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

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to