[Catalyst] Getting Started
Adam Jacob
adam at stalecoffee.org
Fri Aug 5 22:56:27 CEST 2005
On Aug 5, 2005, at 1:38 PM, Christopher H. Laco wrote:
> What about things (data) that are needed for every page on a site,
> like cart count for example. It would seem that the easiest way
> would be to make a plugin instead of having every controller set a
> count in its sub.
One way to do this would be to write a single Controller method that
will populate those global options in the stash, and then $c->forward
to it when you need it. Developing things this way is kind of fun;
as I think it says in the doc's, it starts to feel like putting
little blocks together. :)
So, for example, lets say the values that are there truly are
global. One way to ensure they
always get called it so stick them in the "end" method (the same
place you typically would call something like TT for a view.)
Example:
sub end : Private {
my ( $self, $c ) = @_;
$c->forward('/globalstuff');
$c->forward('YourApp::V::TT') unless $c->res->output;
$c->fillform;
}
I've taken to thinking of the stash as a thing that gets populated by
one or may different methods, depending on what sorts of data I need;
and populating them in Controllers (which call some Model to get the
data itself).
YMMV, and like most things, one way is not necessarily better than
the other.
Adam
More information about the Catalyst
mailing list