Join Jon Peck for an in-depth discussion in this video Validating data with constraints, part of Learning Symfony2 for PHP (2014).
-The Symfony Validation component is used…to validate data and forms.…A key concept in Symfony Validation is constraints,…which are a list of rules for an object…that are used to determine the validity of the data.…Each rule is an assertion that is added…to the entity itself.…For example, an assertion can state a property…must not be blank, and have a numeric range…of, say one to 50.…Even though we're working with forms,…the validation itself takes place on the object,…not the form.…When asking a form to validate itself,…the end result is actually a shortcut…that asks the entity to validate.…
If the entity passes, then the form validates.…Constraints can have numerous targets.…Properties is the most obvious place,…and that's the most common…and easy to use constraint.…For example, a property constraint on a property…storing an area code in the United States…would require that the contents be exactly…three numeric digits.…Similar to properties are getters, which are…the methods that start with get or has,…like the ones generated with entity.…
- Installing Symfony
- Creating a bundle from the console
- Customizing and generating database tables
- Generating controllers
- Creating, editing, and debugging entities
- Displaying and debugging a form
- Rendering content with templates
Skill Level Intermediate
Q: When trying to access the application, I receive an error stating "This script is only accessible from localhost." How can I get around this restriction?
A: The development front controller and configuration scripts are protected by default to only allow access from the localhost. Refer to the video titled “Exploring the Symfony layout” to see how to disable this security.