gog's info

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

Archive for the ‘Zend Framework’ Category

Give your .02$ to the ZF project

without comments

Zend Framework project is about to start working on the 2.0 version. If you are using ZF in your projects, but you are not interested in contributing ideas to the project by joining the zf-contributors mailing list, the least you could do is provide feedback about your ZF experience by answering a survey.

You can find more info at the devzone.

Written by Goran Jurić

December 18th, 2009 at 3:23 am

Posted in Zend Framework

Tagged with ,

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

Removing require_once() calls from Zend Framework

without comments

If you are using Zend_Loader to load your classes in Zend Framework, there is no need for all the require_once() calls that are littered all over ZF files.

Some acctually report big improvements in responsiveness of their applications and increase in number of transactions per second their hardware can handle because require_once() is quite an expensive operation, especially if the required file is already included prior to the call. Read the rest of this entry »

Written by Goran Jurić

October 16th, 2008 at 12:39 am

“Benchmarking” PHP frameworks

without comments

Although I am not a Drupal user, the chance to visit Drupalcon in Szeged (Hungary) appeared and I couldn’t pass on that one. We got there a little bit late, but just in time to hear Rasmus Lerdorfs keynote speech Simple is Hard. There are some really good ideas for optimizing your applications performance and I strongly recommend it for every PHP developer.

There were also some things I really don’t agree that much. He showed a small PHP frameworks “benchmark” measuring the speed (response time and transactions per second) for each of this frameworks to output the simple HTML page printing out the “Hello world” string. Zend Framework (the framework of my choice) didn’t perform all that bad. Symfony was around 30% slower, and Solar was about 2 times faster. If you are really interested in the numbers have a look at the slides from the session.

Read the rest of this entry »

Written by Goran Jurić

August 29th, 2008 at 3:55 pm