I’m doing some XSL transformations in a project I’m involved in right now. The XML documents that are beeing transformed all include a xml-stylesheet processing instruction that I need to read in order to know what stylesheet to use for a specfic document. To my surprise, reading processing instructions from a DOMDocument in PHP was not so easy as one might assume.
Read the rest of this entry »
I’ve been playing around with Zend_Form and Zend Framework 1.5 these last couple of days. Like most people I hade some trouble getting used to the decorator part of the form API. Decorators are used to style form elements for rendering in the browser, adding tags before, after and wrapping the form element itself. After much swearing I finally found this article in the Zend Developer forums that did a pretty good job explaining it.
The next problem I ran into was customizing the form error messages, not just customizing the messages but also localizing them. The framework has default error messages defined for all validators you can use with your form elements but they are kind of stiff and I doubt anyone really want’s to use them. It turns out the solution is really simple.
To attach a validator to a form element you normally write something like this:
$textField = new Zend_Form_Element_Text("myField");
$textField->addValidator(new Zend_Validate_NotEmpty());
If you want to customize the message and maybe even localize it you simply init a validator and manuelly set the message via the setMessage method, like this:
$notEmpty = new Zend_Validate_NotEmpty();
$notEmpty->setMessage("You have to enter a value");
$textField = new Zend_Form_Element_Text("myField");
$textField->addValidator($notEmpty);
If you like to localize the error message, replace the setMessage call with:
$notEmpty->setMessage($this->getView()->translate("You have to enter a value"));
It’s just that simple 
There’s a lot more to localizing a web site then just replacing strings with diffrent languages (for an exelent introduction read the ZF documentation on Zend_Locale). But in this post I will talk about string localization, and especially string localization using gettext and .mo-files with Zend Framework. Read the rest of this entry »
Ran into some trouble the other day while emigrating a PHP solution from our development server to the production server. The application was working fine on the development server but once moved to the production server it started to behave strangely. Read the rest of this entry »