Symfony2 构建表单有数据库字段值重复验证吗

WBOY
Release: 2016-06-06 20:36:15
Original
950 people have browsed it

Symfony里虽然没找到这个验证的说明,但是毕竟是用symfony做的第一个项目,不太熟。

文档中只找到这些验证类型:NotBlank,Blank,NotNull,Null,True,False,Type..

我有一个非id主键,但是不可重复的字段验证。

谁能分享一些自己熟知的实现方法?

回复内容:

Symfony里虽然没找到这个验证的说明,但是毕竟是用symfony做的第一个项目,不太熟。

文档中只找到这些验证类型:NotBlank,Blank,NotNull,Null,True,False,Type..

我有一个非id主键,但是不可重复的字段验证。

谁能分享一些自己熟知的实现方法?

贴个例子,Author对象的email字段加唯一性校验(yaml格式,其他格式的配置可以参考文档)

<code># src/Acme/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Entity\Author:
    constraints:
        - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: email
</code>
Copy after login

文档:http://symfony.com/doc/current/reference/constraints/UniqueEntity.html

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!