0

I want to validate an entity using a values stored in an array which is in the params.

What I tried to do is injecting the array from params.yml (I'm using YAML) via service into a model.

In validation.yml, I tried to use the choice constraint with a callback. but I don't know how to call a method non-static from a different class.

To do this:

- Choice: { callback: [CountryHandler, getCountries] }

getCountries must be static.

Is it possible to do something like that with a method non static? Is it a better idea* to validate the entity with my own constraint as they explain here: http://symfony.com/doc/current/cookbook/validation/custom_constraint.html?

I only have to validate one param and at first sight it doesn't seems a good idea.

1 Answer 1

0

I think that is a better idea because you can re-use in other case and better readability. As show in the documentation you give, you must create 2 files, one for your validator and one for the constraint, if you have dependency, you can inject to Validator declaring a new service with dependancy declared as arguments. After this, you have only to call your constraint as another Constraint.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.