I'm currently using Symfony's validation component as a standalone tool. I'm building an API using Lumen and Doctrine2, and I'm trying to figure out if there is a way to use the UniqueEntity constraint outside of the Symfony2 framework. I've followed this example to attempt to use the UniqueEntity, but I notice that the namespace Symfony\\Bridge\\Doctrine\\Validator\\Constraints\\UniqueEntity
doesn't even exist in the standalone package. Has anyone else gotten this work, or do I have to write my own uniqueness validator?
I create the validation with a yml, you can also create intro model.
In my case this is example:
# src/SClinicBundle/Resources/config/validation.yml
Cf\SClinicBundle\Entity\CfIndicationsTemplates:
constraints:
- Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
fields: name
message: cf.indications_template.name.unique
properties:
name:
- NotBlank: { message: "cf.indications_template.name.not_blank" }
- Length: { min: 2, max: 100, minMessage: "cf.indications_template.name.min_length", maxMessage: "cf.indications_template.name.max_length" }
templateIndication:
- NotBlank: { message: "cf.indications_template.templateIndication.not_blank" }
status:
- NotBlank: { message: "cf.indications_template.status.not_blank" }
- Choice: { choices: [0, 1], message: "cf.indications_template.status.choices" }
datetimeR:
- DateTime: { message: "cf.indications_template.datetime_r.bad_datetime" }
Cf\SClinicBundle\Entity\CfReportTemplates:
constraints:
- Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
fields: name
message: cf.report_template.name.unique
properties:
name:
- NotBlank: { message: "cf.report_template.name.not_blank" }
- Length: { min: 2, max: 100, minMessage: "cf.report_template.name.min_length", maxMessage: "cf.report_template.name.max_length" }
status:
- NotBlank: { message: "cf.report_template.status.not_blank" }
- Choice: { choices: [0, 1], message: "cf.report_template.status.choices" }
datetimeR:
- DateTime: { message: "cf.report_template.datetime_r.bad_datetime" }
Cf\SClinicBundle\Entity\CfMedicalStudy:
constraints:
- Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
fields: name
message: cf.medical_study.name.unique
properties:
name:
- NotBlank: { message: "cf.medical_study.name.not_blank" }
- Length: { min: 2, max: 100, minMessage: "cf.medical_study.name.min_length", maxMessage: "cf.medical_study.name.max_length" }
administerDosesZone:
- NotBlank: { message: "cf.medical_study.administerDosesZone.not_blank" }
status:
- NotBlank: { message: "cf.medical_study.status.not_blank" }
- Choice: { choices: [0, 1], message: "cf.medical_study.status.choices" }
datetimeR:
- DateTime: { message: "cf.medical_study.datetime_r.bad_datetime" }
You can reviewer my example and try compare with you code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.