1

With symfony2, when I create a form from a controller, I was able to send parameters:

$form = $this->createForm(
    new articleType(
        $localedefault,
        $this->get('request')->getLocale(),
        $depotCat,
        $this->get('security.context')
    ),
    $article
);

I recovered these parameters from the constructor of my ArticleType.

With symfony3, I put this :

$form = $this->createForm(
    ArticleType::class,
    $article,
    array(
        $localedefault,
        $request->getLocale(),
        $depotCat,
        $this->get('security.authorization_checker')
    )
);

but this method doesn't work.

2
  • Please format your code, as it helps readability and is more likely to attract answers. I have edited your question accordingly. Commented Mar 21, 2016 at 11:48
  • ok sorry,i would do better next time Commented Mar 21, 2016 at 15:51

1 Answer 1

2

Use configureOptions in your class, then: setDefault('myOption', []).

Upon instantiation:

$form = $this->createForm(
    ArticleType::class,
    $article,
    array(
        'myOption'=>array(...)
    )
);

And then in buildForm you'll have a proper key in the options array.

Sign up to request clarification or add additional context in comments.

3 Comments

in my class, how can i add this options in the function configureOptions.this function accept 'optionResolver' only
Have you tried to implement configureOptions in your ArticleType class according to the documentation? I didn't post completely working code. See the docs, then everything will look reasonable.
it's good, I understood how it works.thank you very much for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.