我正在尝试将RequestStack注入到Symfony 5中的可重用包中:
use Symfony\Component\HttpFoundation\RequestStack;
class ICatcherSeo extends Bundle
{
function __construct(RequestStack $requestStack) {
$RequestStack = $requestStack;
}
我的services.yaml:
App\ICatcher\Seo\:
resource: '../bundles/ICatcher/Seo/*'
autowire: true
这会抛出一个错误:
Too few arguments to function App\ICatcher\Seo\ICatcherSeo::__construct(), 0 passed in D:\SERVER-7_2\htdocs\compasswebdesign\vendor\symfony\framework-bundle\Kernel\MicroKernelTrait.php on line 74 and exactly 1 expected
发布于 2020-09-11 22:28:33
您不应该向包中注入任何东西,因为包的代码不应该在包中(只有一些特定的操作和配置)。
捆绑包的代码,就像项目的代码应该在控制器、侦听器、服务中一样,这取决于您的目标是什么。
https://stackoverflow.com/questions/63776158
复制相似问题