Development

#4852 (sfForm: getName convience method)

You must first sign up to be able to contribute.

Ticket #4852 (closed enhancement: fixed)

Opened 8 months ago

Last modified 8 months ago

sfForm: getName convience method

Reported by: snoerd Assigned to: fabien
Priority: minor Milestone: 1.2.0 RC1
Component: form Version: 1.2.0 BETA2
Keywords: Cc:
Qualification: Unreviewed

Description

When binding a sfForm to a request parameter I find myself often searching for the nameformat of the form. Usually I end up with something like the code below when I don't know the nameformat by heart:

$form = new CreateForm(); 
$form->bind($request->getParameter(str_replace('[%s]','',$form->getWidgetSchema()->getNameFormat())));

A convenience method would make it much nicer, and you don't have to look up the naming in your formclass files:

class sfForm
{
...
  public function getName()
  {
    return str_replace('[%s]','',$this->widgetSchema->getNameFormat());
  }
...
}

The initial example would then be:

$form = new CreateForm();
$form->bind($request->getParameter($form->getName()));

Change History

11/07/08 15:19:29 changed by mahono

It that case it would be even simpler to only have one single method:

$form->bindRequest($request);

But Im afraid for the sake of decoupling this will not make it into the sfForm class. ;-)

I suggest to put something like that in the form base class of your project.

11/17/08 12:45:54 changed by fabien

  • version set to 1.2.0 BETA2.
  • milestone set to 1.2.0 RC1.

11/17/08 12:52:11 changed by fabien

  • status changed from new to closed.
  • resolution set to fixed.

(In [13060]) [1.2] added a sfForm::getName() method (closes #4852)

11/17/08 12:53:42 changed by fabien

(In [13061]) [1.2] added a sfForm::getName() method (closes #4852)

11/17/08 12:53:55 changed by fabien

(In [13062]) [1.2] added a sfForm::getName() method (closes #4852)

11/17/08 15:30:33 changed by snoerd

thanks for fixing!

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.