how to read default values in a symfony 1.4 form?

173 Views Asked by At

I have a symfony form that its initialized with this code

$this->form =new MyForm();
$this->form->setDefault('myValue',"value");

now if I go to MyForm.class.php and execute

echo $this->getObject()->get('myValue');
die();

on configure() method, it doesnt print anything. Same happens in BaseMyForm.class.php.

Am I doing something wrong?

if I print the entire widget in the html with

<?php echo $form['myValue']->renderError() ?>
<?php echo $form['myValue']->render() ?>

it loads correctly.

1

There are 1 best solutions below

0
Jhoan Nicolas Andres Becerra Q On BEST ANSWER

It seems I was wrong about how form builder works, when you pass data through $this->form->setDefault(); it is not loaded in the configure method. If you need to pass data to your configure method you have to do it through your builder, in my case it would be something like:

$this->form =new MyForm(array(),array("MyValue","value");

and then to read it you need to use

$this->getOption('MyValue');

in your configure method

seen on Pass a variable to a Symfony Form