[Catalyst] Form handling, urls and web design
Bill Moseley
moseley at hank.org
Tue Jan 24 15:09:40 CET 2006
On Tue, Jan 24, 2006 at 09:04:37AM +0000, Alex Kavanagh wrote:
> > I stay away from default. Use an empty path instead.
>
> Why do you stay away from default?
It doesn't work like other actions. First, it doesn't pass arguments
relative to the controller, rather all arguments from root:
Request: http://localhost:3000/path/to/controller/arg1/arg2
package App::C::Path::To::Controller;
sub default : Private {
my ( $self, $c, @args ) = @_;
# @args = (path,to,controller,arg1,arg2)
sub foo : Path {
my ( $self, $c, @args ) = @_;
# @args = (arg1,arg2)
Second, with "default" match is not set and action is always "default",
but when using Path they are set just like any other matched
controller.
The only place I use default() is my main application module. That's
where I serve semi-static content.
> > sub edit : Local {
> > my ( $self, $c, $id ) = @_;
> >
> > my $form = $c->stash->{form} = App::Form::Admin::Organization->new( $id );
> >
> > return $c->internal_redirect('list', { message => 'Invalid Organization Selected' } )
> > unless $form;
> >
> > # Now validate and update
> > $form->update_from_form( $c->req->parameters )
> > if $c->form_posted;
> > }
> >
>
> Um, where is internal_redirect defined? Is it a plugin? What makes it
> different from a normal $c->res->redirect ?
It's when I want to show another controller but without the extra
round trip to the client.
=item internal_redirect action @args
This does a sub-request and returns. This is useful for jumping to
another action and making uri_for work relative to the forwarded action (instead
of the originally matched argument).
Action is relative to namespace unless it starts with a slash. If action is
undefined then the redirect is just to namespace (for use with undefined : Path
actions). @args is passed directly to the subrequest.
$action should be a public path.
=cut
sub internal_redirect {
my ( $c, $action, @args ) = @_;
unless ( defined $action ) {
$action = $c->action->namespace;
} else {
$action = join '/', $c->action->namespace, $action unless $action =~ m!^/!;
}
$c->res->body( $c->subreq( $action, @args ) );
return;
}
--
Bill Moseley
moseley at hank.org
More information about the Catalyst
mailing list