用Doctrine搜索几个论点 [英] Search for several arguments with Doctrine

查看:109
本文介绍了用Doctrine搜索几个论点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Symfony2的初学者,我使用教义权限有问题。
我为现有数据库创建了一个实体,我可以使用Doctrine在数据库中使用findById,findByAuthor等函数进行搜索。
我的下一步是创建一个HTML表单,用户可以输入几个参数。
我的目标是,Doctrine现在在数据库中搜索与所有/至少一个参数匹配的所有实体。
我希望我可以使用一个输入数据的实体,但不知道如何。

I'm a total beginner with Symfony2 and I have a problem using Doctrine right. I habe created an entity for an existing database and I can use Doctrine to search within the database using the findById, findByAuthor etc. functions. My next step was to create a HTML form where the user can enter several arguments. My goal is, that Doctrine now searches the database for all entities, who match all/at least one of the arguments. I hoped that I can do this using an entity with the typed in data but I don't know how.

希望你明白我的意思,可以帮助我:)

Hopefully you understand what I mean and can help me :)

greets

推荐答案

你需要做这使用自定义查询。这通过 DQL 大部分。

You will need to do this using custom queries. This is done through DQL mostly.

至于使这个看起来不错,你需要创建一个自定义存储库类,如果尚未完成查询。这似乎有点开销。我经历了这个阶段,寻找替代品。但是最后,这很简单。

As for making this seemless, you will need to create yourself a custom repository class if not already done to put the query into. It seems like a bit of a overhead. I went through that phase of looking around for alternatives too. But in the end, it's quite simple.

当要求实体类型的存储库时,Doctrine将为您提供一个类的实例,它将是透明的。

When asking for the repository for the entity type, Doctrine will just provide you with an instance of your class and it will transparent.

这篇关于用Doctrine搜索几个论点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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