How to perform logic if findBy’Field’ does match?

假装没事ソ 提交于 2020-01-07 08:23:07

问题


I trying to do some logic if my inputed form email matches one found in the database.

How do I make the comparison if the findBy’Field” returns the whole collection instead of just the field I want to compare to? I'd think it should be done without using a foreach loop as that would kinda defeat the purpose of using my findBy method.

An Example:

$formEmail = $form->get('email')->getData();

existingEmail = $em->getRepository(‘UserBundle:User’)->findOneByEmail($formEmail);
// or existingEmail = $em->getRepository(‘UserBundle:User’)->findByEmail($formEmail);

if ($formEmail == $loggedEmail){
    //perform some logic here
}

回答1:


try this

$formEmail = $form->get('email')->getData();

$existingEmail = $em->getRepository('UserBundle:User')->findOneByEmail($formEmail);

if ($existingEmail){
    //found
}else{
    //not found
}


来源:https://stackoverflow.com/questions/41166604/how-to-perform-logic-if-findby-field-does-match

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!