Just another question:
What about the session? Is it supposed to be handled as model and the accessors to it should be placed in the business logic, or it should be handled as temporary data that could be handled by the controllers and passed to the model by the controllers?
I always have to access session variables in every place, views, controllers and models.
To the views, the controllers could simply assign view variables. But for controllers, I could handle the session by the model and controllers could retrieve it from there, or the controllers could handle the sessions, setting and passing it to the models and to the views.
What's the best approach?
Ramses
What about the session? Is it supposed to be handled as model and the accessors to it should be placed in the business logic, or it should be handled as temporary data that could be handled by the controllers and passed to the model by the controllers?
I always have to access session variables in every place, views, controllers and models.
To the views, the controllers could simply assign view variables. But for controllers, I could handle the session by the model and controllers could retrieve it from there, or the controllers could handle the sessions, setting and passing it to the models and to the views.
What's the best approach?
Ramses
On Tue, Sep 23, 2008 at 7:18 PM, Matthew Weier O'Phinney <matthew@zend.com> wrote:
> I would like to ask about "where should I put the code". SometimeThe quick start clearly shows extending the Zend_Form object in a custom
> I am asking myself, should I put this code into model or leave in
> controller or create own library class..?
>
> For example, there is a new user account registration process. I have
> to show a registration form in a controller (should I create the form
> object in the controller or create new class extended from the
> Zend_Form or create the form object in the controller...?),
class.
This is open for debate. Some consider such validation part of the
> after submitting there is need to validate data (should I do it
> directly in the controller or in a library...?),
decistioning/branching logic of the controller. Others feel it should be
part of the model. I've done both approaches. They're both valid.
Deciding what view and model to use (and what data to pass to each) is
*definitely* in the realm of the controller. This is not business logic
-- it's considered application logic. And yes, there *is* a difference.
Application logic is geared around the workflow of a request, while
business logic is related to the objects making up your model, and is
typically data oriented.
Your model is a class, or set of classes. Somewhere, at some point, you
> then I save a user account data (again, do it in the controller, model
> or a library which will cooperate with a model...?) into the database
> table...
have to pass data to the model. This should happen in the controller.
Your models should work with data sources. And, currently, we're doing
> I'm thinking that controller should respond to all user requests (and
> should not contains any business logic) and through (library) objects
> works with models and access data sources and do anything else.
exactly what you suggest in the Quick Start.
That's all these methods are doing -- they're simply returning the
> I am asking you because when I looked over your quick start
> application, there is in GuestbookController two protected functions -
> _getModel() and _getGuestbookForm() and, maybe I am totaly wrong, but
> this doesn't fit in my concept of M/V/C separation (I would rather put
> this code into separeted class object which returns a concrete form
> object).
concrete instances of the model and form objects, which are defined in
separate classes. Somehow, some way or another, the controller needs to
get these instances. How else would you suggest grabbing them?
The Quick Start. ;)
> I know there is no dogma about this question and probably this be up
> to each programmer, but are there any advices/propositions/rules how
> to divide a ZF (or whatever other MVC) application and where to put
> the code? I still haven't found sufficient answers for my questions.
>
> What do you think abou it? What is your best practise?
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论