Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Symfony 5中获取项目或根目录_Php_Symfony_Solarium - Fatal编程技术网

Php 如何在Symfony 5中获取项目或根目录

Php 如何在Symfony 5中获取项目或根目录,php,symfony,solarium,Php,Symfony,Solarium,我使用Symfony 5和日光浴室。我想在我的控制器(从AbstractController扩展)中获取项目目录(或根目录) 我看到了一些内核的Anwer,创建了新的服务,等等 但是,它不只是一个调用projectdir而不创建一些定制服务的函数吗 谢谢 您不需要为此提供任何服务。您可以从控制器中的容器中获取 $this->getParameter('kernel.project_dir') 另一种方法是把它绑在yaml上 _defaults: bind:

我使用Symfony 5和日光浴室。我想在我的控制器(从AbstractController扩展)中获取项目目录(或根目录)

我看到了一些内核的Anwer,创建了新的服务,等等

但是,它不只是一个调用projectdir而不创建一些定制服务的函数吗


谢谢

您不需要为此提供任何服务。您可以从控制器中的容器中获取

$this->getParameter('kernel.project_dir')

另一种方法是把它绑在yaml上

    _defaults:
        bind:
            # pass this value to any $projectDir argument for any service
            # that's created in this file (including controller arguments)
            string $projectDir: '%kernel.project_dir%'
因此,您可以将每个服务和控制器作为$projectDir注入

public class YourController {
   public function index(string $projectDir){
        // Your code
   }
}

public class YourService {
   public function __construct(string $projectDir){
        // Your code
   }
}