David Apshid
David Apshid

Reputation: 311

how to set default value in backend form?

i generated admin in Symfony 1,4. I have there DoctrineChoice. I would like set this list select in action.class.php.

I copied executeNew to action.class.php, but i dont can set default value on load page.

$this->form = $this->configuration->getForm();
$this->news = $this->form->getObject();
$this->form['author_id']->getWidget()->setOption('choices', '2');

doesnt work. Is this possible?

Upvotes: 1

Views: 1060

Answers (2)

redshark1802
redshark1802

Reputation: 924

or just simply like this in lib/form

$this->setDefault('fieldname', $value);

Upvotes: 1

Damien
Damien

Reputation: 5882

This code should work:

$this->form['author_id']->getWidget()->setDefault(2);

But I have to say that if you want it clean, this code belong to the Form class, not the action.

Upvotes: 0

Related Questions