sisko
sisko

Reputation: 9910

Symfony2 calling controller function from buildform function

How do I call a custom function in the controller class of my bundle from the buildForm function of the AbstractType class of the same bundle?

My AbstractType:buildForm function works fine and generates my desired form but I have to add an extra field which will be a dropdown field of selectable options.

I need to dynamically generate the options for the dropdown list from data in the database - which I am already generating in the controller class.

Upvotes: 0

Views: 171

Answers (1)

sisko
sisko

Reputation: 9910

Thanks to @sjagr, I've found a working solution.

Previously I had tried the following:

$form = $this->createForm(new SalesType(), new Sale(),
   array(
        'action' => $this->generateUrl('sales_add'),
        'method' => 'POST',
        'arguments' => array(1,2,3,4,5,6,7)
    )
)

But I hadn't paid enough attention to the resulting error message: The option "arguments" does not exist. Known options are: "action", "allow_extra_fields" ...

I changed the arguments index of the array above to allow_extra_fields and my array arguments data was then available in the $options parameter of the buildForm function

Upvotes: 0

Related Questions