当前位置: 动力学知识库 > 问答 > 编程问答 >

symfony2 - What is the most 'professional' way to check if value send via form exist in database

问题描述:

I am a basic user of Symfony2 and doctrine. I'm thinking what is the best solution to check if a value sent via form exist in database. For now my only solution is:

  1. Receive form data in controller
  2. Use doctrine, make query to check if value exist in database
  3. Send appropriate message to view depending on result of query

I suppose it is not the most professional way. Can somebody give me any guidelines? I heard something about own validator but I have never used it. Is it a good idea? Maybe a better way is to use doctrine inside Entity? Maybe in-build asserts can solve the problem? As I know rather not but I could omit something...

Thanks for help in advance.

网友答案:

Maybe in-build asserts can solve the problem?

A big Yes! ;-)

Take a look at UniqueEntity constraint . It will do the job for you.

分享给朋友:
您可能感兴趣的文章:
随机阅读: