Symfony2 如何获取表单提交的数据得到一个数组?

问题:

In symfony 2 controllers, every time I want to get a value from post I need to run:

$this->getRequest()->get('value1');
$this->getRequest()->get('value2');

Is there any way to consolidate these into one statement that would return an array? Something like Zend's getParams()?


答案:

You can do $this->getRequest()->query->all(); to get all GET params and $this->getRequest()->request->all(); to get all POST params.

So in your case:


$params = $this->getRequest()->request->all();
$params['value1'];
$params['value2'];


by 雪洁 2014-11-04 02:12:03 2094 views
我来说几句

相关文章