The problem with saying that all validation needs to happen in the Model is that for practical reasons it does not work very well. The most common reason is that the Model usually does not deal with all the input from the request. Some input is intended for the Controller or the View logic specifically -- but it still needs to be validated and filtered. Another case is where a simple and generic Model is used because, for example, only the mix of fields is changing (e.g. CRUD). In these cases it can be a cleaner design to do validation in the Controller for each variation and share a common Model.

However, I think the goal should be for the Model to validate all the data it is interested in.

The MVC pattern is a guideline for dependencies and layer separations (i.e. domain and presentation), but should not get in the way of good design. Even those dependencies can be flexed for the needs of the design. And sometimes it make sense to do some, or even all validation, in the Controller.


Sam Davey wrote:
I'm not worried as such... but my problem is the flexability of it all. Don't get me wrong, thats one of the best features of the Zend Framework, integrating any subsystems I design using ZF into my legacy system will be incredibly easy compared to the vast majority of other frameworks available (cakePHP, symfony etc etc).

I was just trying to clarify that the comprehensive tutorial I was following was not adhering to MVC, and as such I shouldn't use the examples in the tutorial as a basis for future development since all of the domain logic was shoved in the controller.

I gather that by quoting 'MVC is simply a matter of keeping the domain, application and view logic in separate layers' then you agree with my post. i.e. the controller should not contain any validation or database interaction since this is domain logic. And the controllers main purpose is to invoke methods on a the model based on input from the view.

I understand the principle of MVC... it is a design pattern. Therefore from my point of view its a moot point to say that ZF is not a strict MVC framework since the strictness comes from your own design. I just wanted to make sure that my take on it was correct so that I can enforce this strictness.

I don't agree with your point that ' we clearly can't discuss about Model when we don't have ORM
functionality yet to put domain logic into'.

Although ORM would certainly be useful for the majority of Models, they are certainly not dependant on ORM. Any database interaction can be done using Zend_Db, granted you sacrifice some development time but basically achieve the same thing. Besides, some models may not relate to a database table at all.


From: "Mislav Marohnić" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
CC: "Sam Davey" <[EMAIL PROTECTED]>, [email protected]
Subject: Re: [fw-general] Advice for Model design
Date: Thu, 21 Sep 2006 16:19:36 +0200

Sam,

Your approach, although basic, is not incorrect... I don't understand
what you're worrying about. MVC is simply a matter of keeping the
domain, application and view logic in separate layers.

Keep in mind that ZF is not a strict MVC framework. Sure it has
Controller and View, but it's more like a "make your own MVC" thing.
And we clearly can't discuss about Model when we don't have ORM
functionality yet to put domain logic into.


Reply via email to