我在使用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;
}
}
最后,约束:
properties:
userID:
- NotBlank: ~
password:
- NotBlank: ~
好吧,不知道为什么,但无论我在userID和密码输入字段中输入什么,我总是得到一个
This value should not be blank.
消息。如果我在用户对象上使用Debug::dump()
方法,我发现所有属性都是空的。
有什么想法吗?
答案 0 :(得分: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;
}