zend-framework doctrine, and mvc pattern: what should connect data between models and forms?

Posted by Skirmantas on Stack Overflow See other posts from Stack Overflow or by Skirmantas
Published on 2010-05-30T21:39:56Z Indexed on 2010/05/30 21:42 UTC
Read the original article Hit count: 165

Filed under:
|
|

I am learning Zend Framework and Doctrine.

I am wondering what is the best practice to connect forms to models and vice versa. I don't know where I should put my code.

I have seen in Zendcast video tutorials where author creates methods like mapFormToRecord and mapRecordToForm in form class. Well I guess it is very handy when form is sophisticated and uses many records. Is it a good practice? I somehow believe that form-class should not need to know about data-records.

And sometimes we might have model which is used in many forms. So It would be handy to have few functions in that model which would help to prepare data for forms. For example to give an array of id=>name pairs so that it might be used in Zend_Form_Element_Select.

However I would like to have a consistency. So I don't want to put this code nor in model nor in form because on different situations I act different. So only controller is what is left to deal it. However this will result in code duplication if one form will be used more than in one controller. Moreover controller gets bloated if form is not from the simple ones.

Or maybe there is a consistent pattern in those data conversions between forms and models? I think that there is. At least in my simple cases. So maybe a separate class could be a solution? Where should I put such class and how should I name it?

Another question: Zend_Form has validators and filter. Doctrine has validators and filters too. Which do we use and when?

What is your way of dealing the connections between forms and models?

(Sorry if it was hard for you to read my text. I don't have enough knowledge of English language to express myself freely)

© Stack Overflow or respective owner

Related posts about mvc

Related posts about zend-framework