您不需要为此提供任何服务。您可以从控制器中的容器中获取。$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 }}https://symfony.com/doc/current/configuration.html#accessing-configuration-parameters