Istiyak Tailor
Istiyak Tailor

Reputation: 17

How to access value of a particular post field in symfony 2.8

I want to access a particular field value when posted, similar to $_POST['title'] in core PHP. How can I achieve this in Symfony 2.8?

So far I have tried using

$request->request->get('name') --- returns all values from post.

$request->request->all() --- same returns all values.

$request->request->get($form->get('name')) -- again same..returns all values

If I pass something in get() it shows nulls, eg:- If I passed $request->request->get('Title') --- returns null.

I have attached the image for better understanding.

Returns All

Returns Blank

Controller

Upvotes: 0

Views: 321

Answers (2)

Jagjeet Singh
Jagjeet Singh

Reputation: 1572

You can do like this :

$request->query->get('Title');
// OR
$request->request->get('Title');
// OR
$request->get('Title');

You can also able to this with Entity:

$article = new Article();
$article->getTitle();

Full Information : https://symfony.com/doc/current/introduction/http_fundamentals.html#symfony-request-object

Upvotes: 1

Istiyak Tailor
Istiyak Tailor

Reputation: 17

I solved it by storing it into a variable, like this

$data = $request->request->get('form');

//or

$data = $request->request->all();

and then accessing it through array keys. $data['Title'];

Upvotes: 0

Related Questions