tags:

views:

27

answers:

1

in the tutorial i can use either:

public function configure() {
    $this->setWidgets(array(
    'type' => new sfWidgetFormChoice(array(
                'choices' => Doctrine_Core::getTable('Gender')->getTypesForForm(),
                'expanded' => false,
                'multiple' => false,
    ))
));


    $this->widgetSchema['type'] = new sfWidgetFormChoice(array(
                'choices' => Doctrine_Core::getTable('Gender')->getTypesForForm(),
                'expanded' => false,
                'multiple' => false,
            ));
}

to define a widget.

i wonder which i should use and why there is 2 ways of writing this?

thanks

+2  A: 

They're equivalent; setWidgets() is cleaner: it doesn't assume that $this->widgetSchema is an array (accessing $this->widgetSchema directly breaks the encapsulation), plus, it allows you to set multiple widgets at once.

Piskvor
I guess "cleaner" is subjective :-) I like to be able to do my widget setup explicitly grouped by widget (eg ->setDefault(), ->setLabel()) :-)
richsage
I meant "cleaner" as in "encapsulated" - if, in the next version, $this->widgetSchema stops being an array (and becomes e.g. an Object), $this->widgetSchema['something'] = $somethingelse will break.
Piskvor