【问题标题】:Symfony 3 - must be an instance of FormFactoryInterface, instance of FormFactory givenSymfony 3 - 必须是 FormFactoryInterface 的实例,给定的 FormFactory 的实例
【发布时间】:2023-03-03 02:57:01
【问题描述】:

我想从服务中取出我的表单,但无论我做什么,它都行不通。

我在 YML 中有服务

services:      
  myservice:
     class: AppBundle\Service\Myservice
     arguments: ["@doctrine.orm.entity_manager","@form.factory"]

然后在 AppBudle\Service\Myserivce.php:

namespace AppBundle\Service;

use Doctrine\ORM\EntityManager;

use Symfony\Component\Form\FormBuilderInterface;

use Symfony\Component\Form\Extension\Core\Type\TextType;

class Myservice {

protected $em;
protected $formFactory; 

public function __construct(EntityManager $entityManager, FormFactoryInterface $formFactory) {
    $this->em = $entityManager;
    $this->formFactory = $formFactory;
    }   


// GENERATE CALCULATOR FORM
public function generateCalculatorForm() {  


     return  'ffffsdsd';
    }

}

但我得到了一个

可捕获的致命错误:传递给 AppBundle\Service\Myservice::__construct() 的参数 2 必须是 AppBundle\Service\FormFactoryInterface 的实例,给定 Symfony\Component\Form\FormFactory 的实例,在 D:\xamp\ 中调用htdocs\icp\var\cache\dev\appDevDebugProjectContainer.php 在第 409 行并定义了

这里有什么问题?我已经尝试了我在网上找到的几乎所有东西,但无法正常工作。

【问题讨论】:

    标签: php forms symfony service


    【解决方案1】:

    http://php.net/manual/en/language.namespaces.php

    如果名称不完整,则在当前名称空间名称前面添加类/接口名称。

    FormFactoryInterface设置全名或将其添加到use语句中

    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\Form\Extension\Core\Type\TextType;
    use Symfony\Component\Form\FormFactoryInterface;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-02
      • 2019-04-04
      • 2019-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 2021-05-15
      相关资源
      最近更新 更多