The zend-framework doctrine and the mvc template: which layer should bind data between models and forms?

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.

+5
source share
1 answer

I think the controller is the best place to connect models and forms. If you want to prevent the use of large amounts of code to fill out the form, create a fill method in the form that takes the model.

, , . , , , , " ".

2 .

+2

All Articles