我想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()".
手掌心