08.
EntityType Validation: Restrict Invalid programmerId
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
4 Comments
Hello,
I usually do this check for entity direct from the controller, this is not a good practice? For example, in cases where a user can not start a battle with the ID 10 scheduler but can start with the ID 11 scheduler, I would need to do a check for this, how would I do this using the FormType query_builder?
Hey Tiago,
Do validation inside a controller have drawbacks, for example you can't reuse this validation in another controller without code duplication. I don't fully understand what is "scheduler" you mentioned, but in query_builder you have to create a query which returns only valid result of set. There you can use different conditions in WHERE clause and even join other tables, which help you to filter result set. For more complex validation you can use custom callback constraints. Does it make sense for you?
Cheers!
Does the result of the custom query builder determine if there is a validation error? If not, then what?
Hi Vlad!
You're exactly right - the query builder determines if there is a validation error. If the user submits the id "5", and that is *not* found via the query builder (i.e. there IS a user id 5, but it is not one returned by the query builder), then the validation error is thrown.
I talk a bit more about this "sanity validation" here: http://knpuniversity.com/sc...
Cheers!
"Houston: no signs of life"
Start the conversation!