我是symfony的新手需要帮助
当我运行“console debug:event”时,我收到以下错误消息:
App\EventListener\ReservationEventSubscriber::__construct(): Argument #3 ($id) must be of type int, string given, called in /Applica
tions/MAMP/htdocs/E-STock/E-STock_v6/var/cache/dev/ContainerTiaj2qn/getReservationEventSubscriberService.php on line 22
问题是我不知道怎么解决,连我自己都不确定是否真的了解这个问题
这是我代码:
预订事件订阅者:
class ReservationEventSubscriber implements EventSubscriberInterface
{
private $manager;
private int $id;
public function __construct(EntityManagerInterface $manager, TokenStorageInterface $tokenStorage, int $pieceId)
{
$this->manager = $manager;
$this->tokenStorage = $tokenStorage;
$this->id = $pieceId;
}
我已经把我“pieceId”绑定在“service.yaml”上了
parameters:
id: 'secret'
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind:
int $pieceId: '%id%'
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
1条答案
按热度按时间5kgi1eie1#
在'service.yaml'中,您的参数id是字符串,并且在ReservationEventSubscriber中将$id的属性类型设置为整数。
private int $id;
只需将service.yaml中的id设置为interer即可,例如: