[Jifty-commit] r1423 - in jifty: .

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sat Jul 1 16:31:18 EDT 2006

Author: nelhage
Date: Sat Jul  1 16:31:17 2006
New Revision: 1423

   jifty/   (props changed)

 r13508 at phanatique:  nelhage | 2006-06-30 15:09:13 +0200
 Adding a J::M::Cookbook with solutions to commom questions/ How-do-I's.

Added: jifty/trunk/lib/Jifty/Manual/Cookbook.pod
--- (empty file)
+++ jifty/trunk/lib/Jifty/Manual/Cookbook.pod	Sat Jul  1 16:31:17 2006
@@ -0,0 +1,70 @@
+=head1 NAME
+This document aims to provide solutions to common questions of "How do
+I do I<x> with Jifty?" While the solutions here certainly aren't the
+only way to do things, they're generally the solutions the developers
+of Jifty use, and ones that work pretty well.
+=head1 HOW DO I ...
+=head2 Limit access to pages to logged-in users
+The best place to do this is probably in your application'
+L<Dispatcher|Jifty::Dispatcher>. If, for example, you wanted to limit
+access to C</secret> to logged-in users, you could write:
+    before qr'^/secret' => run {
+        unless(Jifty->web->current_user->id) {
+            Jifty->web->tangent('/login');
+        }
+    };
+Then, in your login form component, you would write something like:
+    <% Jifty->web->return(to => '/', submit => $login_action) $>
+The combination of the C<tangent> and C<return> will cause the user to
+be returned to wherever they came from. See L<Jifty::Continuation> for
+more information.
+If you want model-level access control, Jifty provides a ready-built
+ACL system for its models; See L<Jifty::Manual::AccessControl> for
+Finally, you can also allow or deny specific actions in the
+dispatcher, to limit who is able to perform what actions -- see
+=head2 Take actions based on data in URLs
+You can add actions to the request based on data in URLs, or anything
+else, using
+L<Jifty::Request::add_action|Jifty::Request/add_action>. For example,
+suppose you wanted to make the path C</logout> log the user out, and
+redirect them to the home page. You could write:
+    before '/logout' => {
+        Jifty->web->request->add_action( class => 'Logout' );
+        Jifty->web->request->add_action(class     => 'Redirect',
+                                        arguments => { url => '/' });
+    };
+=head2 Pass HTML form input directly to components
+Sometimes, you don't want to take an action based on input from HTML
+forms, but just want to change how the page is displayed, or do
+something similarly transient.
+C<Jifty::Action> is great, but it doesn't have to be the answer to
+everything. For cases like this, it's fine to use typical HTML C<<
+<input>s >>. Their values will be accessible as request arguments, so
+you can fetch them with C<get> in the dispatcher, and they will be
+passed as arguments to top-level Mason components that list them in
+C<< <%args> >>. And don't worry about namespace conflicts with Jifty's
+auto-generated argument fields -- Jifty prefixes all its C<name>s with
+C<J:> so there won't be a problem.

More information about the Jifty-commit mailing list