Re: Your opinion about QuickForm2 API

From: Date: Mon, 16 Apr 2007 09:24:18 +0000
Subject: Re: Your opinion about QuickForm2 API
References: 1  Groups: php.pear.dev php.pear.general 
Request: Send a blank email to pear-dev+get-46225@lists.php.net to get a copy of this message
Bertrand Mansion wrote: > We are in the middle of a discussion Alexey and I about QuickForm2 > API for elements creation and I would like your opinion as well. > At this point, nothing is immutable since we aren't even talking > about alpha stage, so your preferences as users and developers is > interesting. > > To summarize, Alexey would be in favor of this: > > $form->addElement('button', 'aButton', 'Click me please'); > $form->addElement('select', 'aSelect', array('1' => > 'option 1', '2' > => 'option 2')); This is the old (and IMO sometimes confusing) style which is (at least in the current QF) not consistent through the various elements. > While I would be in favor of this: > > $form->addElement('button', 'aButton')->setContent('Click me > please'); > $form->addElement('select', > 'aSelect')->setOptions(array('1' => > 'option 1', '2' => 'option 2')); This style is more "OO-ish" (*g*) and should also be more consistent in usage. +1, therefore [...] > The other point we are discussing is about the extra parameter in > element creation. I suggest we always use an array, even when there > is only one extra parameter. Alexey suggests that we use a scalar if > there is only one extra parameter. For example, for a given "Year" > element which would only accept one configuration parameter > 'startYear', Alexey would use: > > $form->addElement('year', 'aYear', '2007'); > > While I would use: > > $form->addElement('year', 'aYear', array('startYear' => > '2007')); +1 for this last style because it avoids confusion, too, and especially also because sometimes later such elements might get a second, third, ... option. Regards, Mark X'Post: php.pear.dev,php.pear.general -- http://www.markwiesemann.eu

« previous php.pear.dev (#46225) next »