Doctrine - 根据字段检查记录是否存在 [英] Doctrine - check if record exists based on field

查看:12
本文介绍了Doctrine - 根据字段检查记录是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 symfony2 中使用学说,我有一个包含以下字段的简单用户模型:

Using doctrine in symfony2, i have a simple user model with the following fields:

Username
Email
Password

如何根据电子邮件地址加载模型?

How can I load the model based on email address?

推荐答案

$user = $this->getDoctrine()
             ->getRepository('YourBundle:User')
             ->findOneBy(array('email' => $email));

请阅读关于这个的官方教义 orm 文档

这篇关于Doctrine - 根据字段检查记录是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆