开发者

2 different ways to define a widget in symfony, which to use?

开发者 https://www.devze.com 2023-01-01 14:29 出处:网络
in the tutorial i can use either: public fu开发者_如何学Pythonnction configure() { $this->setWidgets(array(

in the tutorial i can use either:

public fu开发者_如何学Pythonnction 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消