提问人:GeorgeLemy 提问时间:9/29/2022 更新时间:9/29/2022 访问量:35
为什么当唯一的 Id 传递是 int 时,这会返回我“字符串给定”
Why this return me 'string given' when the only Id pass is an int
问:
我是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
问题是我不明白如何解决它。 即使我也不了解这个问题^^
这是我的代码:
ReservationEventSubscriber:
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;
}
我已经在'service.yaml'上绑定了我的“pieceId”
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'
答:
0赞
Dan
9/29/2022
#1
参数 ID 是“service.yaml”中的字符串,并将 ReservationEventSubscriber 中 $id 的属性类型设置为整数。private int $id;
只需将 service.yaml 中的 id 设置为 interer,例如:
parameters:
id: 5
评论
id: 'secret'
id: 69