Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: How to organize Catalyst stash

by ruoso (Curate)
on Nov 18, 2010 at 16:34 UTC ( #872296=note: print w/replies, xml ) Need Help??

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.

   /  \

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.


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.)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://872296]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2023-03-24 17:06 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (61 votes). Check out past polls.