FirePHP logging and JSON action helper

4 messages Options
Embed this post
Permalink
HUjuice () FirePHP logging and JSON action helper
Reply Threaded More More options
Print post
Permalink
Sending log to Firebug while you're sending JSON data via the JSON action helper (see: http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.json) is actually (ZF 1.7.0, FirePHP 0.2.1) a bit problematic.
The argument is discussed around (mostly at http://framework.zend.com/issues/browse/ZF-4202).

Keeping all together, the actual simplest working way to make it properly work is:

function jsonAction()
{
    // your code here, assuming that it produces some $data

    // probably you created a logger in some bootstrap step
    $FirePhpLogger = Zend_Registry::get('logger');

    /*
    Since the JSON helper sends its response very early and then exit,
    the logic below vanish the FirePHP logger.
    */
    //$this->_helper->json($data);

    /*
    Suppressing the exit, the JSON helper (in ZF 1.7.0) will disable
    the response sending and will NOT exit
    */
    $json = $this->getHelper('Json');
    $json->suppressExit = true;
    $json->sendJson($data);

    $FirePhpLogger->log($json->encodeJson($data), Zend_Log::INFO);
}

That's all.

Regards,
HUjuice
Christoph Dorn () Re: FirePHP logging and JSON action helper
Reply Threaded More More options
Print post
Permalink
Thanks for the tip.
HUjuice () Re: FirePHP logging and JSON action helper
Reply Threaded More More options
Print post
Permalink
You're welcome!
And it's an idea by you!

Simply, I gave a working example in this forum.
(I've a couple of lines less than you, why?)

FirePHP and wildfire are *fantastic*!
Thank you for your work, it's very very useful and usable...

Ciao,
HUjuice
Christoph Dorn () Re: FirePHP logging and JSON action helper
Reply Threaded More More options
Print post
Permalink
Yes. Thanks for the example in the forum.

Your example code will send the JSON data and then continue executing the request. If you want to stop execution (like the JSON helper does by default) you can use the following code to first flush the FirePHP buffer and then exit manually.

Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
$json->getResponse()->sendResponse();
exit;