我正在尝试访问 Utils 类中的 TokenStorageInterface,因为我需要重用代码并且我不想弄乱控制器内部的内部逻辑。
但是从我的班级访问 TokenStorage 接口时出现以下错误。
类型错误:函数 App\Utils\Ability::__construct() 的参数太少,0 已通过
这是我的课程(我将只发布 __construct ,因为这是相关部分):
<?php
namespace App\Utils;
use Doctrine\ORM\EntityManagerInterface;
class Ability
{
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
}
有什么线索吗?
PS:启用自动装配
添加 config\services.yaml :
parameters:
locale: 'en'
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']