Symfony 5 autowire 注入可重用包
Symfony 5 autowire injection into a reusable bundle
我正在尝试将 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
你不应该向包中注入任何东西,因为你的包的代码不应该存在(只有一些特定的操作和配置)。
你的 bundle 的代码,就像一个项目的代码应该在控制器、监听器、服务中,这取决于你的目标。
我正在尝试将 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
你不应该向包中注入任何东西,因为你的包的代码不应该存在(只有一些特定的操作和配置)。
你的 bundle 的代码,就像一个项目的代码应该在控制器、监听器、服务中,这取决于你的目标。