开发者

Set value of sfwidgetformdoctrinechoice from a parameter

开发者 https://www.devze.com 2023-02-20 11:50 出处:网络
Is there any way to set the value of a sfwidgetformdoctrinechoice from the parameter in actions.php?

Is there any way to set the value of a sfwidgetformdoctrinechoice from the parameter in actions.php?

I know I could change it into a sfWidgetInput instead, but I want the user to be able to be able to ch开发者_C百科oose a record if no parameter is given.

Thanks


Yes! In the configure() method of your form use the setDefaults() method:

public function configure()
{  
    $this->setDefaults(array( 
    'your_widget' => 'your_parameter'
    ));
}

or, more simply, in your action code

$form = new YourForm(array('your_parameter'=> 'your_parameter_value'))

which is easy to understand when you see this:

  /**  
   * Constructor.
   *
   * @param array  $defaults    An array of field default values
   * @param array  $options     An array of options
   * @param string $CSRFSecret  A CSRF secret
   */
  public function __construct($defaults = array(), $options = array(), $CSRFSecret = null)
  {
    $this->setDefaults($defaults);
    ...
0

精彩评论

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