ymfony2在FormType中注入EntityMananag

ymfony2在FormType中注入EntityMananag

本文介绍了Symfony2在FormType中注入EntityMananager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自定义表单类型


Custom form type

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityManager;

class NationaliteitidType extends AbstractType
{
private $doctrine;
private $em;

public function __construct(EntityManager  $em)
{
    $this->em = $em;
}

service.yml
服务:

service.yml services:

fw_core.form.type:
    class: FW\CoreBundle\Form\Type\NationaliteitidType
    arguments:
        entityManager: "@doctrine.orm.entity_manager"

错误:

我必须已经创建了某种类型或其他明显的类型,但确实找不到它。

I must have made an type or something else obvious but realy can't find it.

推荐答案

在您的services.yml中,您无法命名将来的变量,因此请尝试如下操作:

In your services.yml, you can't name your future variables, so try something like this :

services :
    fw_core.form.type:
        class: FW\CoreBundle\Form\Type\NationaliteitidType
        arguments:
            - "@doctrine.orm.entity_manager"

这篇关于Symfony2在FormType中注入EntityMananager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 22:28