On 10.05.2011, at 10:45, dbenjamin wrote: > The service layer should not be responsible of data binding, it should works > only with domain objects since it is a part of the business logic. > The form object is really specific to one frontend and to one framework, it's > the role of the controller to build a domain object from user inputs, and > then to invoke the service. > > I don't want to manipulate forms directly in the service layer, that would > link my business layer to Symfony. > > I don't assign any validator to the form. Validation rules are defined on the > domain object, never on the Form, the Form performs validation automatically > when validation rules are set on the domain object. > Unless there is a way ? > > Even though, if i don't validate with the form, i have no *easy* way to take > my ConstraintViolationList and bind errors to the form. I need it because i > still have to show errors to the user. > I know that i can bind errors to the form with a small piece of code, but > that would be great if it was native. > > The form layer is really great, but this is really a common architecture on > big projects with distributed APIs. > > Since a standalone data binder doesn't exist, a form could be used "only" for > that purpose if we could prevent validation.
Looking at it for a REST use case, I would still want to do the validation, but I do not really need the Form stuff while having a use case for the data binding. I do not know the new Form layer well enough yet to know if its unnecessary overhead, but here is the concept we currently have in the RestBundle for Controller actions that work with both HTML an JSON/XML, though even if HTML isnt needed I would probably still use the following approach for convenience of having the Form layer do the data binding: - action uses the from for data binding and validation - FormInstance is assigned to the view layer or set a target url/route to redirect to - the view layer determines if to use a 4xx status code if validation failed - the view layer calls createView() in case a templating aware encoder is used (aka HTML) - for non templating aware encoders we encode all validation errors As such in the JSON/XML case we can skip the createView() call and the FormInstance will be used for just data binding and validation. Eventually we could also use the FormInstance to be able to auto generate API documentation based on the FormInstance. regards, Lukas Kahwe Smith [email protected] -- 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
