gog's info

<?php echo array_rand(array('web', 'dev', 'computers')); ?>

Archive for May, 2009

From DocBook to PDF using Apache FOP

with 2 comments

Creating user manuals for the software you are building is an important task. Sometimes it is a project requirement but more often than that it is just more efficient having a document to which you can refer users to and stop waisting you precious time explaining the fundamentals of content management systems to novice users instead of actually doing what you are payed for.

Since I do not like to repeat myself I wanted a system that is capable of generating documentation in variety of formats, PDF being the most important one.

DocBook is the first thing that came to mind, but as it is usually the case the things are not so simple as they should be. After playing fore the most part of the day with DocBook and various utilities I decided to write it down for future reference. Read the rest of this entry »

Written by Goran Jurić

May 21st, 2009 at 1:45 pm

Adding filters automatically to your Zend_Form_Element_Text objects

without comments

Although you can create a custom form element as described in ZF manual and set the properties for all instances of this element I really did not like this solution since my application already has a lot of already working forms.

I wanted to add the Zend_Filter_StringTrim filter to all of my text form elements so I decided to just add them on the fly.

Since my forms already extend a custom “MyApp_Form” object (MyApp_Form extend Zend_Form) it was just a matter of intercepting the addElement() method.

So, here it goes, in all its glory:

public function addElement($element, $name = null, $options = null)
{
    parent::addElement($element, $name, $options);
 
    if (is_null($name)) {
        $name = $element->getName();
    }
 
    $addedElement = $this->getElement($name);
 
    if ($addedElement instanceof Zend_Form_Element_Text) {
        if ( ! $addedElement->getFilter('StringTrim') instanceof Zend_Filter_Interface ) {
            $addedElement->addFilter(new Zend_Filter_StringTrim());
        }
    }
}

Since the element is already added to the form using the parent method I didn’t have to check if the element is passed as a string, but does not have a name, or if it’s passed as a Zend_Form_Element object without the name property since the Zend_Form::addElement() already checks for this.

Written by Goran Jurić

May 18th, 2009 at 10:33 am

Posted in Zend Framework

Zend Framework 1.8

without comments

Yesterday Zend Framework 1.8 was released and since I was ill and didn’t have much else to do I decided to have a look and make necessary changes to port our company CMS to the new version.

The new autoloader Zend_Loader_Autoloader is just what I was looking for to easily group the forms and models with my application modules. I definitively recommend to read a great article about the new autoloader at Zend Developer Zone.

The whole process of migrating from ZF 1.7.7 was quite painless I just had to replace:

Zend_Loader::registerAutoload

with

$loader Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('MyApp_');

Zend_Log_Writer_Mail is finally in the stable distribution and It took only couple of lines of code to add this to our application logger so now when stuff go terribly wrong I at least know I will be getting an email about it.

You can view the full list of changes in the 1.8 release here.

I look forward to playing with Zend_Navigation and see if we how could we use it to cleanup some of the mumbo-jumbo we are currently doing with ACLs and navigational elements.

Zend_Validate_Db_RecordExists doesn’t look like much, but it makes me happy to remove some custom code because it is now supported in the framework.

Written by Goran Jurić

May 3rd, 2009 at 1:03 am

Posted in Zend Framework

Tagged with