gpt4 book ai didi

Symfony4 - 函数 App\Manager\ImageManager::__construct() 的参数太少,传递了 0 个,预期正好有 1 个

转载 作者:行者123 更新时间:2023-12-02 18:34:53 25 4
gpt4 key购买 nike

我试图在我的 ImageManager.php 的 services.yaml 中获取一个参数,但它不起作用,我无法解决此错误。

这里是错误:

Type error: Too few arguments to function App\Manager\ImageManager::__construct(), 0 passed in C:\wamp64\www\SymfonyAPI\var\cache\dev\ContainerZxFSS5S\getImageManagerService.php on line 14 and exactly 1 expected

服务.yaml

parameters:
images_directory: '%kernel.project_dir%/public/uploads/images/'
...

services:
_defaults:
autowire: false
autoconfigure: false
public: true

App\Manager\ImageManager:
arguments:
$targetDir: '%images_directory%'

如果对于 Autowiring 和自动配置我设置为 true 我有此错误:

RuntimeException Cannot autowire service "App\Manager\ImageManager": argument "$targetDir" of method "__construct()" has type "App\Manager\targetDir" but this class was not found.

ImageManager.php

private $targetDir;

public function __construct(targetDir $targetDir)
{
$this->targetDir = $targetDir;
}
<小时/>

完整服务.yml

parameters:
liip_imagine.mozjpeg.binary: /mozjpeg/cjpeg.exe
images_directory: '%kernel.project_dir%/public/uploads/images/'
mozjpg_directory: '%kernel.project_dir%/mozjpg'
locale: 'en'

services:
_defaults:
autowire: false
autoconfigure: false
public: true

App\Manager\ImageManager:
arguments:
$targetDir: '%images_directory%'

App\EventListener\ImageUploadListener:
tags:
- { name: doctrine.event_listener, event: prePersist }
- { name: doctrine.event_listener, event: preUpdate }

App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'

App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']

app.post_processor.my_custom_post_processor:
class: '%kernel.project_dir%/src/Controller/ImageController.php'
tags:
- { name: 'liip_imagine.filter.post_processor', post_processor: 'mozjpeg' }

最佳答案

您正在添加一种 targetDir 类型,并且您的应用程序认为这是某种类,您可以在错误中看到 的类型为“App\Manager\targetDir”,但该类未找到。,如果您使用的是 php 7 或者不将任何内容作为类型,只需将 targetDir 替换为 string 即可,即使您具有 Autowiring true/false 的原因是:

App\Manager\ImageManager:
arguments:
$targetDir: '%images_directory%'

关于Symfony4 - 函数 App\Manager\ImageManager::__construct() 的参数太少,传递了 0 个,预期正好有 1 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48964262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com