Zend Framework 1.8 is upon us!


Thats right, 1.8 is here!

And with it comes with a whole bag load of new features, 4 of which i’m very eager to get using, in Zend_Application, and Zend_Tag, and Zend_Tool, and Zend_Navigation. There is another component which interests me, which is of course Zend_Validate_Db_RecordExists and Zend_Validate_Db_NoRecordExists, which were my small contribution to this release.

Zend_Application is a whole new way to bootstrap you application, and encompasses a whole bag of new features. One of which is a new autoloader, which of course means that the old one has now been depreciated. You can find excellent instruction on upgrading your legacy applications to 1.8′s new autoloader (to avoid the notices it will generate) at Akrabats blog, His famous tutorial has also been updated to encompass 1.8 and its new features. If you want the full low-down of the new autoloader, a slightly more in depth look can be found at devzone

Zend_Tool is The new CLI tool to provide scaffolding for your applications. It will save some of the tedium of setting up an application directory strucure, creating the various bootstrap, htaccess, and other miscelanous files you need to get you application started. Even better news about Zend_Tool, it will set your new application up to use Zend_Application, so you can get started with two of the latest features, simply by starting a new project! (I can’t wait!!)

Zend_Tag is a new component for generating those lovely new-fangled tag clouds you see on everyones blogs. It is a pretty simple to use component, but possibably my favourite feature is its weighting system, which i can see being useful for more than just generating simple tag clouds, but, with a little extension, also for relevancy matching. This is something i will definatly be adding to my current CMS application project which is consuming so much of my time currently. Also worth looking at, is DASPRiD’s screencast detailing how to use Zend_Tag to generate clouds, and how the decorators work. He even demonstrates it being used in a CLI application (Genius!), and as the author of Zend_Tag, obviously watching this screencast will be like getting instruction straight from the horses mouth.

Zend_Navigation is a nice way to create menus for your site. Its also a great way to optimise your site for indexing by search engines. It also provides a way to avoid using the dreded action(viewhelper|stack) for creating menus! Put simply this component should be used by everyone. I know i will be using it as soon as i get the chance to work it into my projects.

  1. #1 by kenrick on June 2, 2009 - 8:08 pm

    hey that new validator is great, though for an idiot like me I had a gotcha when using it in conjunction with extending a Zend_Form. You can’t just call it from inside of the init() function, and expect it to be able to get at the values being passed so you can validate against stuff. Uh lemme explain:

    myForm extends Zend_Form
    {
    function init()
    {
    $this->addElement(….array(
    ‘validators’=>array(
    array(‘Db_NoRecordExists’,
    false,
    array(‘users’,
    ‘email’,
    array(
    ‘field’=>’id’,
    ‘value’=>$this->_userId // this has to come from someplace!
    // you can just do a $this->id->getValue(), since
    // this is inside the init() function…
    )
    ))
    )
    ))
    }
    }

    well I just had to modify the __construct method of myForm to accept some kind of value that could be used in the init() function for check records in the database. Maybe this is totally obvious to everyone else, but I’m working on no sleep[ and 6 cups of coffee right now…

    Thanks again for the contribution.

  2. #2 by Ryan on June 2, 2009 - 8:51 pm

    Kenrick, Thank you for the comments, and I’m glad you like it :D

    I have come across the same problem before, and I found that the way I dealt with this was to add the validator to the relevant element later than init(), as I usually have a process method in my forms which takes the post data, and a table row, and sets defaults, and determines if the post is empty, and then calls isValid, this was the ideal place for me to add this validator to the element, as I could get the ID from the row being passed to the method. and insert the validator just before calling isValid.
    This doesn’t really save any overhead, but it sure looks prettier than overloading the constructor.

  3. #3 by Marcelo on July 22, 2009 - 6:27 pm

    I confess i didn’t test it, but there is one thing i dint understand. How is the form populated when editing (nothing posted yet).

    Shouldn’t $users->getEditUserForm($post) also take $id as parameter just in case nothing was posted?

    Sorry if i am talking BS, but i am very used to my massed spaghetti code pattern =/

  4. #4 by Marcelo on July 22, 2009 - 6:30 pm

    Btw, this post is awesome. Thank you for teaching good code!

  5. #5 by Marcelo on July 22, 2009 - 6:51 pm

    Great, i commented the wrong post… hahaha

    stupid!

    right one => Creating simple, extendible CRUD, using Zend Framework

Comments are closed.