2016-04-22 34 views
1

我有一个在loginAction,看起来像这样要求的值

Controller "SystemBundle\Controller\SystemController::loginAction()" requires that you provide a value for the "$request" argument (because there is no default value or because there is a non optional argument after this one).

以下是路由:

system_login: 
path: /login 
defaults: { _controller: SystemBundle:System:login} 

和形式:

<form method="POST" id="lgn" action="{{ path('system_login') }}"> 
     <span class="fa fa-times close" onclick="lgn()" ></span><br /> 
     <span>Login:</span> 
     <input type="email" placeholder="Email" required="required" name="umail" /> 
     <input type="password" placeholder="Password" required="required" name="upass" /> 
     <button type="submit">login</button> 
    </form> 

请帮助...

+3

您是否正确导入Symfony \ Component \ HttpFoundation \ Request类? –

回答

3

我想在你的控制器问题。试试这个:

use Symfony\Component\HttpFoundation\Request; 

class FooController extends Controller 
{ 

    public function loginAction(Request $request) 
    { 

     if($request->getMethod() == 'POST') 
     { 
      $mail = $request->request->get('umail'); 
      $pass = $request->request->get('upass'); 
      $em = $this->getDoctrine()->getManager(); 
      $rep = $em->getRepository('SystemBundle:User'); 

      $user = $rep->findOneBy(array("email"=>$mail,"pass"=>$pass)); 
      if($user) 
      { 
      $id = $user->getId(); 
      $type = $user->getType(); 

      return $this->render('@System/Pages/admin/index.html.twig'); 
      } 
     } 
    } 

}

+1

谢谢,我在使用语句中添加了webkit包! –

0

我在这里加入这个答案,因为它是为OP正确的解决方案,但他选择了不正确的答案。感谢Kuba Birecki对此答案的评论。

Symfony无法自动装载$ request参数,因为它与可用的自动装载参数类型列表不匹配。这很可能是因为当您添加Request typehint时,您的IDE为错误的类添加了一个use语句。

确保use声明适用于Symfony\Component\HttpFoundation\Request