http://qs321.pair.com?node_id=872296


in reply to How to organize Catalyst stash

First of all, you shouldn't do that.

You are coupling controller, view and model logic in your controller action. You shouldn't "prepare things for the view" in the controller, but rather just "prepare the context for the view". That meaning, if you're in a inner context (such as one individual customer), the controller should set this up. But NEVER build data structures that are specific for one view.

You should use more of the TT programming language for such things. In a lot of cases, your controller action will be just empty, because context was defined in an earlier chained action, and you just need to dispatch to one specific view (most of the time, to one specific template).

That means that you are going to do a lot of "search" calls directyly in your template, but THAT'S OK!!. That's how MVC is supposed to be, remember. It's not a layered schema, it's a triangle.

    M
    ^^
   /  \
  V<---C

Which means, the model is accessed both by the controller and the view, and the controller just dispatches to the view. It is very important that you do not couple the controller to the view, otherwise, implementing an alternative view (RSS, ATOM, email) will be very hard.

daniel

Replies are listed 'Best First'.
Re^2: How to organize Catalyst stash
by sundialsvc4 (Abbot) on Nov 19, 2010 at 14:23 UTC

    In actual practice, as we all know, sometimes you do have to give-way on this design point.   Sometimes, the cleanest way to do something is to have the object produce presentation-ready information about itself.   (If it can do so using templates, so much the better.)

    What I was specifically cautioning against, is the idea of “involving a third-party.”   The problem being, not only that this third-party is wholly dependent upon both of its customers, but also that it is quite easily overlooked.

    I would also say, en passant, that sometimes I have seen exactly this kind of messy dependency ... showing up in ... the templates!   “Templates are ‘code,’ too.”

    There are guidelines here, and rules of thumb, but no rules.   It would be delightful if there were, but these considerations always go very deeply into “the guts of” the application design.   (And, I do intend to have made these comments in accompaniment to, not “in rebuttal to,” yours.   I understand and agree with your points.)