访问控制器中的请求
<?php
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class TestController extends Controller
{
//Inject Request HTTP Component in your function then able to exploit it
public function myFunctionAction(Request $request)
{
//BASICS
//retrieve $_POST variables from request
$postRequest = $request->request->get('my_data');
//retrieve $_GET variables from request
$getRequest = $request->query->get('my_data');
//get current locale
$locale = $request->getLocale();
}
}
请注意,注入的 Request 对象适用于当前请求(它可能或可能不等于主请求)。