I am learning Zend Framework and Doctrine.
I am wondering what is the best practice for connecting forms to models and vice versa.
In some cases, it is convenient to load data from the model into the form class. Let's say a very unique class that uses many models.
In other cases, it is convenient to use methods in the model class that prepare data for the forms. Suppose it can have a method that returns an array prepared for the select-options element, so this method will be useful for many forms.
I would like to have consistency and always keep this logic in one layer.
I think the controller is not the right place, because I want to keep it clear and simple.
What is your practice to achieve this goal (combine models with forms)?
- I come to the conclusion that I have to prepare my models for all my needs. If I have to deal with many models, I will have a service level (is that the right term?) That will connect these models. Thus, a model or service will have methods for hydrating data for forms. And he will be able to accept data from form values.
source
share