我想public从控制器类 SYmfony4 中的函数中获取目录我尝试了三种类型,但都是徒劳的。print $this->get('kernel')->getProjectDir();print $container->getParameter('kernel.project_dir');print $this->appKernel->getProjectDir();第一个显示这样的错误信息,我猜有一些提示......Service "kernel" not found: even though it exists in the app's container, the container inside "App\Controller\MemberController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services. Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "MemberController::getSubscribedServices()".
1 回答
手掌心
TA贡献1942条经验 获得超3个赞
你很接近。AbstractController::getParameter()
在您的控制器方法中尝试:
$this->getParameter('kernel.project_dir') . '/public';
仅供参考,这实际上不是一个好的做法,并且会增加测试的复杂性。更好的解决方案是使用依赖注入。
- 1 回答
- 0 关注
- 183 浏览
添加回答
举报
0/150
提交
取消