我正在尝试将从表单输入的电子邮件地址与数据库中已有的电子邮件地址进行比较,我认为最好的方法是使用 findByEmail 方法。
我希望在表中找到特定条目的电子邮件地址,但它会返回整个条目(名字、姓氏等等……)。如何仅在表格中找到条目的电子邮件地址?
我知道我可以使用 aforeach
来遍历条目,但我认为这有点违背了使用findByEmail
函数的目的。
这是我到目前为止所尝试的:
$formEmail = $form->get('email')->getData();
$personEmail = $em->getRepository('UserBundle:User')->findByEmail($formEmail); //Should just find the email address of a person in the database.
var_dump($personsEmail); //returns the whole row associated with the email address (first name, last name…..)
var_dump(if($formEmail == $personEmail));die; //returns false when it should be true because it finds the whole row instead of the email address