指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

如何获取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()
    }
}