Getting all request parameters in Symfony 2

后端 未结 3 1754
梦毁少年i
梦毁少年i 2020-12-13 08:05

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

$this->getRequest()->get(\'value1\');
$this->getRequest()->ge         


        
3条回答
  •  遥遥无期
    2020-12-13 08:47

    With Recent Symfony 2.6+ versions as a best practice Request is passed as an argument with action in that case you won't need to explicitly call $this->getRequest(), but rather call $request->request->all()

    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
    use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
    use Symfony\Component\HttpFoundation\RedirectResponse;
    
        class SampleController extends Controller
        {
    
    
            public function indexAction(Request $request) {
    
               var_dump($request->request->all());
            }
    
        }
    

提交回复
热议问题