Doctrine2和魔术师有更多的领域不工作? [英] Doctrine2 and magic finders with more fields not working?

查看:103
本文介绍了Doctrine2和魔术师有更多的领域不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Doctrine2允许您使用基于字段名称的魔术查找器进行查询。如果您有一个名为 User 的实体,您应该可以调用 $ repo-> findOneByUsernameAndPassword()有用户名和密码字段。

Doctrine2 allows you to query using magic finders based on field names. If you have an entity named User you should able to call $repo->findOneByUsernameAndPassword() assuming that the entity has username and password fields.

我如何将参数传递给魔术师?如何查询实际上是关系的字段?

How can i pass parameters to magic finders? How to query when the field that is actually a relation?

我尝试过:

$repo->findOneByUsernameAndPassword('Jhon', 'password')

$repo->findOneByUsernameAndPassword(array('Jhon', 'password'))

但是我收到错误:


实体'用户'没有字段'usernameAndPassword'。因此,您可以
不调用'findOneByUsernameAndPassword'

Entity 'User' has no field 'usernameAndPassword'. You can therefore not call 'findOneByUsernameAndPassword'


推荐答案

我找不到对于这种语法与Doctrine 2的任何参考,虽然可能与Doctrine 1。我自己使用它,并记住有问题,使其工作。
现在你宁愿这样做我想:

I couldn't find any reference for this syntax with Doctrine 2, though it was possible with Doctrine 1. I used it myself then and remember having problems getting it to work. Now you would rather do this I guess :

$repo->findOneBy(array('username' => 'Jhon', 'password' => 'password'));

您可以在这个Doctrine 2文档§

You can get more information in this § of the Doctrine 2 documentation

这篇关于Doctrine2和魔术师有更多的领域不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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