New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a php validation for forms #17

Open
cedriclombardot opened this Issue Sep 20, 2011 · 7 comments

Comments

Projects
None yet
3 participants
@cedriclombardot
Member

cedriclombardot commented Sep 20, 2011

Actually the form validation is in HTML5 managed by the generator and in php managed by user like in http://symfony.com/doc/current/book/validation.html#constraint-configuration, i imagine to create a proxy class chain between bundle and real model class

  • BundleYourModel extends AdmingeneratedBundleYourModel
  • AdmingeneratedBundleYourModel extends YourModel

And in AdmingeneratedBundleModel something like :

public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        parent::loadValidatorMetadata(); //If is callable

        //And auto generated
        $metadata->addPropertyConstraint('gender', new Choice(array(
            'choices' => array('male', 'female'),
            'message' => 'Choose a valid gender.',
        )));
    }

What do you think about ?

@deepgreen

This comment has been minimized.

Show comment
Hide comment
@deepgreen

deepgreen Nov 24, 2011

The alternative to php is using yaml file that define the constraints - as per Symfony. I do see the technical advantage with your proxy class, I guess it is consistent approach using code generation, but validation can be very "fussy" and quite likely to be changed, Using yaml as the default lowers the barrier to get a site up "without php code". i.e. A whole site generated without code, including form validation! From your link above

Acme\BlogBundle\Entity\Author:
properties:
gender:
- Choice: { choices: [male, female], message: Choose a valid gender. }

deepgreen commented Nov 24, 2011

The alternative to php is using yaml file that define the constraints - as per Symfony. I do see the technical advantage with your proxy class, I guess it is consistent approach using code generation, but validation can be very "fussy" and quite likely to be changed, Using yaml as the default lowers the barrier to get a site up "without php code". i.e. A whole site generated without code, including form validation! From your link above

Acme\BlogBundle\Entity\Author:
properties:
gender:
- Choice: { choices: [male, female], message: Choose a valid gender. }

@cedriclombardot

This comment has been minimized.

Show comment
Hide comment
@cedriclombardot

cedriclombardot Nov 26, 2011

Member

Yes i'm agree with the approch of yaml validators. thats why i've not already write code. I'm shared between extract automatically validations from model constraints (eg Unique column) -> so generate a php because can't do otherwise in cache. And lets devs write the validator yaml.

Do you know if a good men have do a generate validators command ? Could be a good alternative.

Member

cedriclombardot commented Nov 26, 2011

Yes i'm agree with the approch of yaml validators. thats why i've not already write code. I'm shared between extract automatically validations from model constraints (eg Unique column) -> so generate a php because can't do otherwise in cache. And lets devs write the validator yaml.

Do you know if a good men have do a generate validators command ? Could be a good alternative.

@deepgreen

This comment has been minimized.

Show comment
Hide comment
@deepgreen

deepgreen Nov 26, 2011

+1 for yaml then. I believe that the first step is to clearly indicate to users how they can validate their model using existing validation constraints provided by symfony - without code change and of course coupled with html 5. i.e. Just extending the documentation as a start. This is why your generator approach is so powerful! When this recommended approach is written up this then it can be automated directly in the builders or commands. I think eventually the command approach fits better since this is decoupled from the builders and likely simpler. But can be deferred.
Put another way. In my opinion the generator should not in this early release do any more - you are generating symfony components which are very well documented, stable and extensible. Linking the generator to their documentation etc. Just a thought.

deepgreen commented Nov 26, 2011

+1 for yaml then. I believe that the first step is to clearly indicate to users how they can validate their model using existing validation constraints provided by symfony - without code change and of course coupled with html 5. i.e. Just extending the documentation as a start. This is why your generator approach is so powerful! When this recommended approach is written up this then it can be automated directly in the builders or commands. I think eventually the command approach fits better since this is decoupled from the builders and likely simpler. But can be deferred.
Put another way. In my opinion the generator should not in this early release do any more - you are generating symfony components which are very well documented, stable and extensible. Linking the generator to their documentation etc. Just a thought.

@cedriclombardot

This comment has been minimized.

Show comment
Hide comment
@cedriclombardot

cedriclombardot Nov 28, 2011

Member

OK so agree for all to move into roadmap 1.1 and method will be a command line to init the yaml into the folder of the bundle ?

Member

cedriclombardot commented Nov 28, 2011

OK so agree for all to move into roadmap 1.1 and method will be a command line to init the yaml into the folder of the bundle ?

@deepgreen

This comment has been minimized.

Show comment
Hide comment
@deepgreen

deepgreen Nov 28, 2011

Sounds like a good plan.

deepgreen commented Nov 28, 2011

Sounds like a good plan.

@ioleo

This comment has been minimized.

Show comment
Hide comment
@ioleo

ioleo Nov 8, 2012

Member

@cedriclombardot @CayetanoSoriano i think this is no longer neccessary as you can define validation constraints directly in the entity useing Annotations,

i think we should close this issue

Member

ioleo commented Nov 8, 2012

@cedriclombardot @CayetanoSoriano i think this is no longer neccessary as you can define validation constraints directly in the entity useing Annotations,

i think we should close this issue

@cedriclombardot

This comment has been minimized.

Show comment
Hide comment
@cedriclombardot

cedriclombardot Nov 14, 2012

Member

Yes and no for me validate an entity is not the same as validate a form. I can want to add differents constrainst depends if i'm in front or back for example

Member

cedriclombardot commented Nov 14, 2012

Yes and no for me validate an entity is not the same as validate a form. I can want to add differents constrainst depends if i'm in front or back for example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment