[Catalyst] Cascading action dispatching
Matthew Pitts
mpitts at a3its.com
Fri Oct 19 22:16:11 GMT 2007
My apologizes if this has been addressed before, I couldn't find
anything in the archives.
I'm trying to figure out a way to have my Cat app dispatch in a way that
would allow multiple actions in the same namespace and have them called
in succession until one of them actually handles the request.
I have a client that really likes base-level URLs, like
"/shoppingmallxyz", and wants to use them for landing pages that are
functionally different. In some of these cases the base-level URL paths
are really just monikers for things that are retrieved from the DB and
if it exists, then a page is rendered.
For example, I want to have a controller Center that has an action like
the following:
sub base_lookup : PathPart('') Chained('/') Args(1) {
my ( $self, $c, $moniker ) = @_;
my $center = $c->model('Common::Center')
->find_by_moniker($moniker);
if ( $center ) {
... do some stuff to fill stash and specify template ...
} else {
... give notice that this action couldn't handle the request ...
}
}
And then another controller Promotion that has an action like this:
sub base_lookup : PathPart('') Chained('/') Args(1) {
my ( $self, $c, $moniker ) = @_;
my $promo = $c->model('Common::WebPromotion')
->find_by_moniker($moniker);
if ( $promo ) {
... do some stuff to fill stash and specify template ...
} else {
... give notice that this action couldn't handle the request ...
}
}
If the Center::base_lookup action doesn't find a center from the given
moniker it bows out and the dispatcher then goes on to find the
Promotion::base_lookup action which will essentially to the same thing
as the Center::base_lookup action but instead use the base url argument
as a moniker to lookup a promotion.
I guess, if neither action can handle the request, then the dispatcher
would just fall back to default.
I was thinking I might be able to accomplish this with a call to
$c->dispather->dispatch(), but in a simple test I did this just results
in a recursive call.
I greatly appreciate any help with this.
Thanks,
--
Matthew W. Pitts
Software Engineer
mpitts at a3its.com
336.202.3913 (mobile)
A3 IT Solutions, LLC
www.a3its.com
More information about the Catalyst
mailing list