Porting Agavi’s shiny error handler to Zend Framework

Agavi-logoLast Tuesday I joined the Webtuesday Zurich meeting. David Zülke (project lead, Munich) gave a talk on Agavi Framework.

Agavi is a general purpose PHP application framework built around the Model-View-Controller architecture originally based on the Mojavi 3 Web application framework written by Sean Kerr. It provides a rich toolset that solves most of the routine problems in Web application development. (…)

There are some great ideas and programming techniques behind Agavi and a very bright engineering team. Congrats, David, that was a great presentation of a great project! Agavi is not yet well known in PHP community but you definitely should give it a try! There’s a well though-out architecture behind it.
There will be a webcast of David’s presentation available soon on Webtuesday Zurich.

Well, I’m going to stick with Zend Framework for the near future. One tiny little thing that bothered me in Zend Framework was the fact, that I had to write my own ErrorController and error view script. It can be done in a pretty easy way by following the instructions in the ZF Quick Start. But I would have preferred this to be integrated in a nice way like in Agavi (introduced in 0.11, “shiny” exception template). When I saw its exception handler template I was simply astonished! Wow!

A drop dead gorgeous exception template with eye candy embedded as inline SVG

Check this out: http://zfskeleton.onlime.ch/index/foo

agavi_zf_exception

Porting Agavi’s shiny exception template to Zend Framework was a piece of cake. I grabbed the template from Agavi 1.0.1 (located in /src/exception/templates/shiny.php) and made some tiny modifications.

All you need is an ErrorController and the modified shiny.phtml view script. You can grab both from our Subversion repository:

zfsekeleton is our Zend Framework “Hello World” demo application. It’s built on Zend Framework 1.8.x best practices and uses Zend_Application. Below you’ll find our ErrorController.
Have fun!

20 Responses

  1. Chrigu
    Jun 17, 2009 - 12:34 PM

    Sweet!

  2. Sebastian
    Aug 05, 2009 - 07:31 PM

    Great! Thank you very much for sharing this fine peace of code!

    Best regards
    Sebastian Fahrenkrog

  3. Udo Schochtert
    Sep 11, 2009 - 10:19 AM

    “A drop dead gorgeous exception template” describes it quite well!

    Thanks for adapting and sharing!

    Small improvement:
    You should mention to add to the application.ini file

    ; set error controller view to shiny
    resources.frontController.errorview = shiny

    This would also be the place where you would easily reenable the default error view “error”.

    Best, Udo

  4. NorthernLight
    Nov 16, 2009 - 11:24 AM

    Very good error template, I really like it, but one little thing, it raise an exception in some browser because it could generate a non valid Xml document error.

    To prevent this to happend, simply replace this line:

    by this line:

    In the original line, $requestParams is printed without being escaped by htmlspecialchars and can result to generating non valid XML.

    Great work overall,

    Best

  5. NorthernLight
    Nov 16, 2009 - 11:26 AM

    Add with escaped code
    Replace:
    <?php echo htmlspecialchars(print_r($requestParams)); ?>
    by
    <?php echo htmlspecialchars(print_r($requestParams, true));
    ?>
    I hope it’ll display this time…

  6. christian
    Nov 28, 2009 - 08:11 PM

    oh wow! that is absolutely amazing! Thanks man! Great work

  7. Greg
    Nov 29, 2009 - 12:17 AM

    It’s really great but it doesn’t go with ZFDebug.
    Anyone has tried to solve this conflict?

  8. Csiszár Attila
    Nov 29, 2009 - 01:55 PM

    Thanks! Its a really fantastic errorview!
    However I changed it a little to output different content in production and development mode.

    @greg: I tried it. The fact is that ZFdebug html output generate some non valid xhtml tags and this causes xml rendering error in Firefox.

    The latest ZFDebug source code (checked out from svn) seem to be solve this issues however first you have to switch your view’s doctype to xhtml.

    In your Zend Application bootstrap:

    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(‘viewRenderer’);
    $viewRenderer->initView();
    $viewRenderer->view->doctype(‘XHTML1_TRANSITIONAL’);

    I tried to use this snippet only in ErrorController, but i have no success. I think this is related to this bug:

    http://www.zendframeworkinaction.com/2008/02/24/careful-where-you-set-your-doctype/

  9. Greg
    Nov 29, 2009 - 11:50 PM

    @Csiszár I tried it to no avail :(
    still parsing error.

  10. Greg
    Nov 30, 2009 - 01:08 AM

    I solved it at last! Great!

  11. Juan Felipe Alvarez Saldarriaga
    Nov 30, 2009 - 02:44 PM

    Great! looks so pretty ^_^

  12. iezzip
    Nov 30, 2009 - 08:46 PM

    @NorthernLight: Thanks for the bug report.
    fixed in r3066

    Checkout my short documentation (in German) about the zfskeleton demo-app:
    http://wiki.onlime.ch/dev:zf#demo-applikation

    If you don’t like to grab my code from Subversion, you can download the full project: zfskeleton.zip

    And for those who are still looking for a good hosting provider that does support latest PHP 5.3 versions and Zend Framework, checkout Onlime Webhosting (Switzerland):

    Onlime Webhosting

  13. bsagols
    Feb 20, 2010 - 10:54 AM

    Wow! So nice… Great work, really. It helps me a lot while developing.
    Thanks for sharing this.
    PS: I have a XML parsing error some times though. I’ve disabled svg ($svg=false) always to fix this. Worth to know.

  14. Frank
    Mar 20, 2010 - 01:14 PM

    Pretty cool, but is it possible to replace the SVG graphics with normal ones? The doctype is causing some issues.
    ZFDebug for instance is unable to work due to this error.

  15. Miguel Pinto
    Apr 11, 2011 - 05:20 PM

    I’ve implemented this on a demo project it works fine on development, but when you change to production and aim to a non existing page it doesn’t show anything, i end up with a blank page.

  16. rasti
    Jan 31, 2012 - 06:24 PM

    Wow, this is awesome:) I’ve been working on Agavi 3 years now and i missed this error layout in may zf projects during development. Thank You.

Trackbacks/Pingbacks

  1. Zend Framework – mega zestawienie : W drodze ku szczęściu
  2. Beautify Zend Framework project error pages – Elink Media
  3. Zend Framework – INICIO « Oscar Viana's Weblog
  4. LittleBig error controller

Leave a Comment

css.php