如果findBy'Field匹配,如何执行逻辑? [英] How to perform logic if findBy’Field’ does match?
本文介绍了如果findBy'Field匹配,如何执行逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果findBy'Field返回值为0,那么如何进行比较?如果我的输入表单电子邮件与数据库中找到的电子邮件匹配,整个集合,而不仅仅是我想比较的领域?我认为应该在不使用foreach循环的情况下完成,因为这会违背使用findBy方法的目的。
一个例子:
$ formEmail = $ form-> get('email') - > getData();
$ b existingEmail = $ em-> getRepository('UserBundle:User') - > findOneByEmail($ formEmail);
//或existingEmail = $ em-> getRepository('UserBundle:User') - > findByEmail($ formEmail);
$ b $如果($ formEmail == $ loggedEmail){
//在这里执行一些逻辑
}
解决方案
试试这个
$ formEmail = $ form-> get('email') - > getData();
$ existingEmail = $ em-> getRepository('UserBundle:User') - > findOneByEmail($ formEmail);
if($ existingEmail){
//找到
} else {
//找不到
}
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
}
解决方案
try this
$formEmail = $form->get('email')->getData();
$existingEmail = $em->getRepository('UserBundle:User')->findOneByEmail($formEmail);
if ($existingEmail){
//found
}else{
//not found
}
这篇关于如果findBy'Field匹配,如何执行逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文