Today I wanted to change the custom validation error messages that are generated when using Zend_Form. This isn’t as easy as I first hoped, because even with all of the documentation on the ZF site, I still had some problems understanding exactly what the Zend_Validate class needed to receive in order to display my custom errors.
I wanted to write a set of functions available to me from the view to do some repetative tasks, such as converting a number to a set monetary format. It was obvious to me that I needed to write a custom view helper, but I had some small problems along the way that are worth mentioning.
Well, when looking to simplify some actions and views that present JSON data to pass back from AJAX queries, I was pointed in the direction of the ContextSwitch action helper. One of the default contexts available, is the JSON context, which will disable all layout, and output serialized versions of any variables found in the view. This sounded perfect for what I wanted to achieve.
In my first post below, I covered how to create a FC plugin to ensure that a user is authenticated when they access every controller.
As part of our layout, we want to include a generic style sheet in each page, and a custom style sheet for each controller to each rendered page. As in the previous post, we wanted effectively to run some code in each and every controller, but did not want to have to include the code in each and every controller. As we already had a FC plugin that was handling the authentication, I decided to modify this to set a view variable that can be accessed from the layout.
On our latest site, we are splitting the actual website into 3 different applications. Although some will be screaming “use Zend’s module feature!”, there is a good reason why we want to do this. Mainly, it’s because, the actually front-end advertising website will be hosted on a different domain to the actual content-rich back-end.