可捕获的致命错误:传递给"...\FormType :: __ construct()的参数1必须实现接口

Nic*_*cks 5 php symfony doctrine-orm

我想打电话entityManagerformType.我不明白为什么这不起作用.

FormType:

private $manager;

public function __construct(ObjectManager $manager)
{
    $this->manager = $manager;
}
Run Code Online (Sandbox Code Playgroud)

控制器:

$form = $this->createForm(ProductsType::class, $products);
Run Code Online (Sandbox Code Playgroud)

服务:

apx.form.type.product:
    class: ApxDev\UsersBundle\Form\ProductType
    arguments: ["@doctrine.orm.entity_manager"]
    tags:
        - { name: form.type }
Run Code Online (Sandbox Code Playgroud)

错误:

可捕获致命错误:传递给MyBundle\Form\FormType :: __ construct()的参数1必须实现接口Doctrine\Common\Persistence\ObjectManager,没有给出,在vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry中调用. PHP在第90行并定义

Cer*_*rad 3

假设您的 services.yml 文件正在加载,并且您将其复制粘贴到内容中,那么您有一个简单的拼写错误:

# services.yml
class: ApxDev\UsersBundle\Form\ProductType
should be
class: ApxDev\UsersBundle\Form\ProductsType
Run Code Online (Sandbox Code Playgroud)