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);
...
精彩评论