ZF & Zend_Form

07May08

So I’ve been using ZF more and more, and have come across another reason Zend Framework is just superior imo. Zend Form!

All developers have had the same issues with Forms, and keeping it a) reusable, b) clean, c) contained. Zend_Form does this all. At first it may seem a little confusing, especially if you aren’t familiar with OOP and Decorators, but it’s just another opportunity you get to learn by example. Here is a simple form of mine that lets you add a club, and it’s located in: Project/app/forms/

class forms_AddClub extends Zend_Form {
public function __construct($options = null) {

parent::__construct($options);

$this->setName('register');
$this->setAttrib('enctype','multipart/form-data');

$fields = array();
$empty = new Zend_Validate_NotEmpty();
$empty->setMessage('is required');

$name = new Zend_Form_Element_Text('name');
$name->setLabel('Club Name');
$name->setRequired(true);
$name->addValidator($empty);
$fields[] = $name;

$addy = new Zend_Form_Element_Text('address');
$addy->setLabel('Street Address');
$addy->setRequired(true);
$addy->addValidator($empty);
$fields[] = $addy;

$city = new Zend_Form_Element_Select('cityID');
$city->setLabel('City');
$city->setMultiOptions(array('1'=>'Dallas', '2'=>'Addison'));
$fields[] = $city;

$state = new Zend_Form_Element_Select('stateID');
$state->setLabel('State');
$state->addMultiOption('1','Texas');
$state->setAttrib('disabled', 'disabled');
$fields[] = $state;

$zip = new Zend_Form_Element_Text('zip');
$zip->setLabel('Zip');
$zip->setAttrib('class', 'il');
$zip->setAttrib('size',7);
$zip->setRequired(true);
$zip->addValidator($empty);
$zip->addValidator(new Zend_Validate_Int);
$fields[] = $zip;

$website = new Zend_Form_Element_Text('website');
$website->setLabel('Website');
$website->addValidator($empty);
$fields[] = $website;

$desc = new Zend_Form_Element_Textarea('description');
$desc->setAttrib('cols', 27);
$desc->setAttrib('rows', 6);
$desc->setLabel('About');
$desc->addValidator($empty);
$fields[] = $desc;

$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Add Club!');
$submit->setIgnore(true);
$fields[] = $submit;

$this->addElements($fields);

$this->clearDecorators();
$this->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => '

    ')) ->addDecorator('Form'); $this->setElementDecorators(array( array('ViewHelper'), array('Description'), array('Label', array('separator'=>'')), array('HtmlTag', array('tag' => 'li')) )); // buttons do not need labels $submit->setDecorators(array( array('ViewHelper'), array('Description'),
array('HtmlTag', array('tag' => 'li', 'class'=>'submit-group')),
    )); } }

Then all I do in the controller is $form = new Forms_AddClub(); and I can call methods like $form->isValid(); or just echo $form and I am done! Yeah, it’s nice!

Advertisements

The Zend Framework team conducted a 2hour QA session earlier today, and I was only able to catch the first half of it and here are some of the key parts that I caught wind of I wanted to share with the rest of the world.

Future of ZF
The roadmap of ZF stretches far, far beyond the current location with both an active community & an active core team. With discussions with CMS vendors, JS Frameworks, and intent to integrate ZF into these “unspoken” third party vendor style partnerships not only is ZF growing vertically but also horizontally.

They also are excited about php 5.3 with namespaces, late static binding, and keeping ZF in parallel (to a degree) with the language (php):

We want to be a driving force in the community in shaping the future of the language

Zend Layout
A question was brought on the best practice of having a different layout defined for each module in Zend_Layout, and it was concluded that simply having an abstract class per Module that Controllers extended which defined the layout, and any other module specific controller needs would be the best bet to reduce code duplication.

Command Line / Tooling
A lot was discussed about tooling. And they wanted to let the community know that they believe that Tooling goes beyond Command Line and in keeping the integrity of building from the ground up and easily extending to fit custom needs Tooling should be defined outside of command line such as tooling could also be IDE Driven, or even a web based GUI to change configuration and such. After a bit of discussion they wanted to let the community know proposals were being drafted and a lot of notes & discussions had taken place inside the walls at Zend to think of the best way to do this.

Testing
The Zend Core team really liked a lot Fire_Bug a lot (currently in the Proposals section of the wiki) and will look to build on top of this.

There was also discussion around the new suite based off the popular PHPUnit which will allow the test cases to not only work with css selectors and dom queries (as in popular js frameworks currently) but it also will allow a set of utilities for common test, such as (making sure a db incremented properly and such).

SOAP
Was explained why process on this was low, resource problems and such; and that in the near future (1.6 to 2) there will be WSDL generation, easy PHP class plug & play, logging, debugging, etc. support in the SOAP library.

Active Record
As stated above the team was really excited about 5.3 introducing Late Static Binding as they feel it will allow them to implement a “pure” Active Record.

Zend Framework Certification
They let it out of the bag that there will be a ZF Certification in the future, how near.. well that was yet to be determined. 🙂 That’s about all we know about that at this current time.
That’s about all the notes I could take before I had to bail.. thoughts? Did I miss any key features? Let me know!

** Ryan_Brooks from #zftalk showed me his blog on different topic **


So I have had the DISTINCT pleasure of implementing a “new & innovative” navigational control from the brilliant minds of our Creative department at work. Let me lay down a little bit of the ground work of how this surfaced:

Creative doesn’t want navigation to fall below the fold. They don’t want there to be any natural scrolling on the site. Apparently the built in scroll bars in all the browsers just aren’t “creative” enough for there taste. They also want to represent the hiearchy of the sub navigation via a tree structure (hence the Tree). On top of that, they don’t want to confuse the user with showing anymore than one element at a time. So when one parent is invoked all other expanded parents are collapsed(hence the Accodian).

If this wasn’t brilliant enough, remember the first concern.. don’t want to see a scroll bar even though we are jamming 100 links in 4 sections in the sub navigation. So, the last requirement is if one of the “panes” in the accordian section is larger than X height we want to allow them to scroll within the pane.

Which leaves us with a Scrollable TreeCordian which I wrote using MooTools 1.21b.

Check Out My Example, & Feel Free to Review Code w/ Ways to Improve!


MooTools

29Apr08

So I’ve been doing a lot with MooTools JavaScript library for about 10 months now. From beta to now 1.21b. And, it is my favorite framework of choice. So, I will be building a collection of components and Moo plugins for the world to use to share my love and gee!

Look for them to come soon!