I found this question on stack overflow and I have a question about one of the a
ID: 650537 • Letter: I
Question
I found this question on stack overflow and I have a question about one of the answers:
In Zend Framework, forms are typically objects with decorators, but usually (I thought) processing is done using a combination of controllers and models, with the main objective to keep the controller as lightweight as possible, and each object responsible for its own state.
One of the answers said to use the form object itself as the place to encapsulate the form processing members. Is that a good practice?
For some reason that seems awkward to me. But it also seems awkward to do most of the work in either the database abstraction layer (Zend_Db_Table/Row) or the controller. Where is the best place to encapsulate form processing? Should you create separate classes for the form itself and another class for processing the form (which then deals with the DBAL)?
Explanation / Answer
Validation logic belongs in the database, the domain model, and possibly the view model.
I think most frameworks have Model decorators/attributes to define validation and View helpers to render the View from the Model, including client-side validation shininess. So try to let the framework do all that work for you and focus on the Model.
Business logic belongs both in the Model (domain-dependent logic) and the Controller (service-dependent logic).
I tend to weight as much logic as I can in domain Model to keep the Controller light, as you say. But I generally prefer not to inject service dependencies in my domain layer, so some of that logic has to happen in the Controller.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.