docs: section on params in Intro.pod
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Manual / Cookbook.pod
index 3295168..58f48cd 100644 (file)
@@ -21,7 +21,7 @@ placing a C<die()> call in the C<end> action.
 If you're tired of removing and adding this all the time, you
 can easily add a condition. For example:
 
-  die "Testing" if $c->param->{dump_info};
+  die "Testing" if $c->params->{dump_info};
 
 =head2 Disable statistics
 
@@ -127,6 +127,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 +188,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 +199,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 +281,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