2013-08-31 62 views
0

我遇到了由Symfony製作的簡單登錄表單。這裏是控制器的代碼:Symfony表格總是給我「這個值不應該是空白的。」消息

public function loginAction(Request $request){ 
     $user = new User(); 
     $form = $this->createFormBuilder($user) 
     ->add('userID', 'text', array('label' => 'UserID')) 
     ->add('password', 'password', array('label' => 'Password')) 
     ->add('ricorda', 'checkbox', array(
       "required" => false, 
       "mapped" => false 
     )) 
     ->add('login', 'submit')->getForm(); 

     $form->handleRequest($request); 
     Debug::dump($_POST$user); 
     /*if($form->isValid()){ 

     }*/ 
     return $this->render('TDDumbFEBundle:Default:auth.html.twig', array('form' => $form->createView())); 
    } 

和這裏實體類用戶,在這種形式的數據應被存儲,然後驗證:

class User{ 

    private $userID; 

    private $password; 

    public function getUserID(){ 
     return $this->userID; 
    } 

    public function getPassword(){ 
     return $this->password; 
    } 

    public function setUserID($userID){ 
     $this->$userID = $userID; 
    } 

    public function setPassword($password){ 
     $this->$password = $password; 
    } 
} 

finaly,約束:

properties: 
    userID: 
    - NotBlank: ~ 
    password: 
    - NotBlank: ~ 

那麼,不知道爲什麼,但無論我輸入的用戶名和密碼輸入字段,我總是得到一個

​​

消息。如果我在用戶對象上使用Debug::dump()方法,則會發現所有屬性均爲空。

任何想法?

回答

1

簡單的錯字。

public function setUserID($userID){ 
    $this->$userID = $userID;   // *** Change to $this->userID = $userID 
} 

public function setPassword($password){ 
    $this->$password = $password;  // *** Change to $this->password = $password; 
} 
+0

對我感到羞恥...謝謝 – Nemus

相關問題