Re: Re: Your opinion about QuickForm2 API
| From: | Bertrand Mansion | Date: | Mon, 16 Apr 2007 15:51:35 +0000 |
| Subject: | Re: Re: Your opinion about QuickForm2 API | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-46247@lists.php.net to get a copy of this message | ||
Le 16 avr. 07 à 16:59, Justin Patrin a écrit :
On 4/16/07, Bertrand Mansion <golgote@mamasam.com> wrote:This is called "Fluent interfaces" and is not a major hack :) http://martinfowler.com/bliki/FluentInterface.html http://www.mikenaberezny.com/archives/35 -- Bertrand Mansion Mamasam Work : http://www.mamasam.com Blog : http://golgote.freeflux.netWhile 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 is an example for adding a button to a form. The API can get more complex for Date elements and other javascript aided elements.While this *is* more OO-like I don't see the utility in making the call directly like this. It seems more hack-y to me and doesn't take into account the cases where you want to set 2 or more parameters. You *could* have all option-setting methods return $this but that seems like a major hack to me and will only make for really long chains of possibly confusing code. If you feel like going the method way I'd suggest either having people use a temp var or a get function. $el = $form->addElement('button', 'aButton'); $el->setContent('Click me please'); Then put the above in as a "you can also do it this way if you only want to set one option" tip.