这是我的代码:
$form = $this->createFormBuilder($signupAttempt)
->add('email', 'text', array("label" => "your email:"))
->add('password', 'password', array("label" => "your password:"))
->add('passwordRepeat', 'password', array("label" => "repeat password:"))
->getForm();
if ($request->isMethod('POST')) {
$form->bindRequest($request);
$attempt = $form->getData();
$this->changeSomeAttributesOfSignupAttempt($attempt); // this does not work
if ($form->isValid()) { // this is not taking into account the modification made inside changeSomeAttributesOfSignupAttempt
return new Response("data provided are valid - u signiged up!");
}
}
看到我的问题了吗?我想对实体进行一些更改,并希望表单能够意识到这些更改。不幸的是,我所做的更改似乎没有被察觉,因此,validaition.xml 中为类 SignupAttempt 定义的规则没有得到满足。
这是实体SignupAttempt的validation.xml:
<getter property="emailInUseAlready">
<constraint name="False">
<option name="message">signup_attempt.whole.email_in_use</option>
</constraint>
</getter>
和实体类本身:
class SignupAttempt {
protected $id = null;
protected $email = null;
protected $password = null;
protected $passwordRepeat = null;
protected $emailInUseAlredy = true;
public function __construct($email = null, $password = null, $passwordReapeat = null) {
$this->email = $email;
$this->password = $password;
$this->passwordRepeat = $passwordReapeat;
}
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getEmail() {
return $this->email;
}
public function setEmail($email) {
$this->email = $email;
}
public function getPassword() {
return $this->password;
}
public function setPassword($password) {
$this->password = $password;
}
public function getPasswordRepeat() {
return $this->passwordRepeat;
}
public function setPasswordRepeat($passwordRepeat) {
$this->passwordRepeat = $passwordRepeat;
}
public function setEmailInUseAlready($bool) {
$this->emailInUseAlredy = $bool;
}
public function isEmailInUseAlready() {
return $this->emailInUseAlredy;
}
public function isSecondPasswordMatching() {
return $this->password === $this->passwordRepeat;
}
public function import(array $data) {
throw new \RuntimeException("implement this");
}
}
任何的想法?