In the controller, use PrintelBundle \ Form \ XXXType;
class XXXController extends Controller
{
....
public function newAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$entity = new XXX();
$form = $this->createForm(new XXXType($em), $entity);
....
And in the form of type
class XXXType extends AbstractType
{
private $em;
public function __construct($em)
{
$this->em = $em;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$em = $this->em;
........ done
source
share