如何获取app/config/services.yaml的配置文件内容
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
// 1. Include the ParameterBagInterface class
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
// 2. Basically what we do is autoinject the ParameterBagInterface as argument
// inside the method where you need to obtain a parameter from the services.yaml file
// and then, using the get method you can retrieve a specific parameter.
class MyController extends AbstractController
{
public function index(Request $request, ParameterBagInterface $params): Response
{
$uploadsDirectory = $params->get('uploads_directory');
// ... or retrieve them all with $params->all()
}
}
