I am very new to symfony. In other languages like java and others I can use request.getParameter(\'parmeter name\')
to get the value.
Is there anything
public function indexAction(Request $request)
{
$data = $request->get('corresponding_arg');
// this also works
$data1 = $request->query->get('corresponding_arg1');
}
You can Use The following code to get your form field values
use Symfony\Component\HttpFoundation\Request;
public function updateAction(Request $request)
{
// retrieve GET and POST variables respectively
$request->query->get('foo');
$request->request->get('bar', 'default value if bar does not exist');
}
Or You can also get all the form values as array by using
$request->request->all()
You can do it this:
$clientName = $request->request->get('appbundle_client')['clientName'];
Sometimes, when the attributes are protected, you can not have access to get the value for the common method of access:
(POST)
$clientName = $request->request->get('clientName');
(GET)
$clientName = $request->query->get('clientName');
(GENERIC)
$clientName = $request->get('clientName');
I do it even simpler:
use Symfony\Component\HttpFoundation\Request;
public function updateAction(Request $request)
{
$foo = $request->get('foo');
$bar = $request->get('bar');
}
Another option is to introduce your parameters into your action function definition:
use Symfony\Component\HttpFoundation\Request;
public function updateAction(Request $request, $foo, $bar)
{
echo $foo;
echo $bar;
}
which, then assumes that you defined {foo} and {bar} as part of your URL pattern in your routing.yml file:
acme_myurl:
pattern: /acme/news/{foo}/{bar}
defaults: { _controller: AcmeBundle:Default:getnews }