【问题标题】:symfony 3.4 : forms : Use Data Transformerssymfony 3.4:表单:使用数据转换器
【发布时间】:2020-05-29 06:33:48
【问题描述】:

尝试使用数据转换器,加载我的 html 表单时出错

在我的 formType 类中

use Doctrine\ORM\EntityManagerInterface;

class PmpType extends AbstractType
{
    private $entityManager;

    public function __construct(EntityManagerInterface $entityManager)
    {
        $this->entityManager = $entityManager;
    }
}

在我的 app\config\services.yml 中

services:
# default configuration for services in *this* file
 _defaults:
    # automatically injects dependencies in your services
    autowire: true
    # automatically registers your services as commands, event subscribers, etc.
    autoconfigure: true
    # this means you cannot fetch services directly from the container via $container->get()
    # if you need to do this, you can override this setting on individual services
    public: true

但是我收到了这个错误

Type error: Too few arguments to function myApp\Bundle\Form\PmpType::__construct(), 0 passed in \vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php on line 92 and exactly 1 expected

我错过了什么

谢谢你

【问题讨论】:

    标签: forms symfony


    【解决方案1】:

    好的 我不明白为什么,但我必须为我的班级设置服务: 在 service.yml 中,我添加了

        seims_pmp.pmptype:
          class: SEISM\PmpIG56Bundle\Form\PmpType
          arguments: ["@doctrine.orm.entity_manager"]
          tags: [form.type]
    

    现在它正在工作

    【讨论】:

      猜你喜欢
      • 2017-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 2020-10-05
      • 2020-08-03
      • 2018-09-13
      相关资源
      最近更新 更多