$this->getHelper('Json')->suppressExit = true;

Chris, you saved me at least day from having to rewrite all those
Controllers and testing, thank you so very much.

- jake

On Mon, Sep 8, 2008 at 2:24 PM, Jaka Jančar <[EMAIL PROTECTED]> wrote:
> Ahh, yes, this is the beauty of some ZF helpers, stuff just exit()'s =) It's
> the same in Redirector action helper... never mind if I still have stuff to
> do, it just terminates the script.
>
> I wouldn't put logging into the Json helper, that's ugly. I would however
> rewrite it, so it doesn't exit.
>
> I replaced the Redirector helper with my own Goto helper, which does
> something like:
> --
> $this->getResponse()->setRedirect($url, $this->getCode());
> Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->setNoRender();
> Zend_Controller_Action_HelperBroker::getStaticHelper('Layout')->disableLayout();
> --
> You can probably do something similar. Just modify the response and disable
> viewrenderer and layout.
>
> I would do the actual logging in a controller plugin (not helper!). That way
> it's more pluggable.
>
> Regards,
>  Jaka Jancar
>
>
> On 8. Sep 2008, at 20:15, Jake McGraw wrote:
>
>> Hello all, bit of a problem, not sure how to resolve it.
>>
>> We've developed a RESTful JSON API using Zend Framework MVC. The API
>> makes heavy use of the Zend_View_Helper_Json object, each controller,
>> which represents a separate resource does the following when its done
>> processing:
>>
>> $this->_helper->json( $data );
>>
>> All of this was fine and dandy, until it was decided that we need
>> logging to record every request/response to the API. I setup a
>> BaseController which logs the request during preDispatch. Now, my
>> problem is that directly calling $this->_helper->json( $data ) sends
>> the response and exits, so, postDispatch never occurs. I've tried to
>> resolve this by extending Zend_View_Helper_Json as follows:
>>
>> class BaseHelperJson extends Zend_View_Helper_Json
>> {
>>  public function json( $data, $keepLayouts = false )
>>  {
>>   // ... Do some logging ...
>>   parent::json( $data, $keepLayouts );
>>  }
>> }
>>
>> Then during init() I tried replacing the Zend Json Helper with my own...
>>
>> public function init()
>> {
>>  // Do some init...
>>
>>  $this->_helper->removeHelper('json');
>>  $this->_helper->addHelper(new BaseHelperJson());
>>
>>  // Whoops, how do I reference BaseHelperJson??
>> }
>>
>> This causes an error because addHelper() expects
>> Zend_View_Helper_Abstract... regardless, I wouldn't know how to
>> reference my custom helper as $this->_helper->json anyway. So my
>> question: is there any way to resolve this using OOP or Zend MVC magic
>> or will I have to go through each controller and replace
>> $this->_helper->json with something that plays nice with the
>> dispatcher?
>>
>> - jake
>
>

Reply via email to