On Mon, 14 Feb 2011 09:52:11 +0000, Dan Leech <[email protected]> wrote: > I dont think using a getter would solve the problem, as the getter > should always return the value regardless of whether the hypothetical > "field_enabled" flag is true or false. > > the other thing I can think of is overloading the form class bind > method and strip the validation rules conditionally -- but not sure > how easy this will be. > > > My actual use case is: > > class SomeEntity > { > protected $field1 = 'somevalue'; > protected $field2 = 'someOthervalue'; > protected $field3 = 'andAnotherOne'; > > protected $enabledList = array('field1', 'field2'); > } > > then the validation rule: > > if (in_array($field, $enabledList)) { // apply validation } >
You can add another method name "isField1Valid" returning a boolean to validate the field conditionnaly. This method will be validated as it matches the pattern used to find the getters. This is exactly what is done in the example of the doc to validate a field through a method. -- Christophe | Stof -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-devs?hl=en
