Best way to get request object from within Symfony forms?

前端 未结 1 491
自闭症患者
自闭症患者 2021-01-07 06:45

I use Symfony and Doctrine to generate forms for my CMSes. Lately I\'ve been customizing them by setting default values based on specific URL parameters.

For exampl

1条回答
  •  灰色年华
    2021-01-07 07:04

    Whenever I need the context in a form, I'm doing it via constructor injection.

    in the action:

    $this->form = new WhateverForm($whatever, array("context" => $this->getContext()));
    

    in the form:

    $this->getOption("context");
    

    0 讨论(0)
提交回复
热议问题