X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FCookbook.pod;h=e4cf1c5ec9e9e95aee6f262533fffabf83a465f1;hb=b114f90888d21c4a82cfc4dde4df8396af0ac6d2;hp=d076b8d5e181782640e69163e82cb275d7aa883a;hpb=8f8532e19f5998617f0a05eab528012291168e61;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Manual/Cookbook.pod b/lib/Catalyst/Manual/Cookbook.pod index d076b8d..e4cf1c5 100644 --- a/lib/Catalyst/Manual/Cookbook.pod +++ b/lib/Catalyst/Manual/Cookbook.pod @@ -15,13 +15,13 @@ placing a C call in the C action. sub end : Private { my ( $self, $c ) = @_; - die "testing"; + die "forced debug"; } If you're tired of removing and adding this all the time, you can easily add a condition. For example: - die "Testing" if $c->params->{dump_info}; + die "force debug" if $c->req->params->{dump_info}; =head2 Disable statistics @@ -67,7 +67,9 @@ Just use Catalyst::Model::CDBI::CRUD as your base class. 1; Modify the $c->form() parameters to match your needs, and don't forget to copy -the templates. ;) +the templates into the template root. Can't find the templates? They were in the +CRUD model distribution, so you can do B from +the CPAN shell to find them. =head2 Single file upload with Catalyst @@ -127,6 +129,7 @@ Controller: for my $field ( $c->req->upload ) { + my $upload = $c->req->upload($field); my $filename = $upload->filename; my $target = "/tmp/upload/$filename"; @@ -187,7 +190,7 @@ We'll discuss the first variant for now: To log in a user you might use an action like this: - sub 'login' : Local { + sub login : Local { my ($self, $c) = @_; if ($c->req->params->{username}) { $c->session_login($c->req->params->{username}, @@ -198,6 +201,10 @@ To log in a user you might use an action like this: } } +This action should not go in your MyApp class...if it does, it will +conflict with the built-in method of the same name. Instead, put it +in a Controller class. + $c->req->params->{username} and $c->req->params->{password} are html form parameters from a login form. If login succeeds, then $c->req->{user} contains the username of the authenticated user. @@ -276,6 +283,21 @@ to be. And this is all you need to do. +=head2 Pass-through login (and other actions) + +An easy way of having assorted actions that occur during the processing of +a request that are orthogonal to its actual purpose - logins, silent +commands etc. Provide actions for these, but when they're required for +something else fill e.g. a form variable __login and have a sub begin like so: + +sub begin : Private { + my ($self, $c) = @_; + foreach my $action (qw/login docommand foo bar whatever/) { + if ($c->req->params->{"__${action}"}) { + $c->forward($action); + } + } +} =head2 How to use Catalyst without mod_perl @@ -339,6 +361,14 @@ authentication, authorization, and access check phases. For more information see the FastCGI documentation, the C module and L. +=head1 Forwarding with a parameter + +Sometimes you want to pass along arguments when forwarding to another +action. This can easily be accomplished like this: + + $c->req->args([qw/arg1 arg2 arg3/]); + $c->forward('/wherever'); + =head1 AUTHOR Sebastian Riedel, C