How to get form values in Symfony2 controller

前端 未结 13 1499
挽巷
挽巷 2020-12-12 19:17

I am using a login form on Symfony2 with the following controller code

public function loginAction(Request $request)
{
    $user = new SiteUser();
    $form          


        
13条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 20:00

    I got it working by this:

    if ($request->getMethod() == 'POST') {
        $username = $request->request->get('username');
        $password = $request->request->get('password');
    
        // Do something with the post data
    }
    

    You need to have the Request $request as a parameter in the function too! Hope this helps.

提交回复
热议问题