From: Kennedy Clark Date: Thu, 21 Sep 2006 02:07:39 +0000 (+0000) Subject: Updates and additions to the tutorial. X-Git-Tag: 5.7099_04~345 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=f2c10d65222a90ee666a98daeff0120508061b52 Updates and additions to the tutorial. --- diff --git a/lib/Catalyst/Manual/Tutorial/AdvancedCRUD.pod b/lib/Catalyst/Manual/Tutorial/AdvancedCRUD.pod index 96fb811..22d4ecc 100644 --- a/lib/Catalyst/Manual/Tutorial/AdvancedCRUD.pod +++ b/lib/Catalyst/Manual/Tutorial/AdvancedCRUD.pod @@ -2,6 +2,7 @@ Catalyst::Manual::Tutorial::AdvancedCRUD - Catalyst Tutorial - Part 8: Advanced CRUD + =head1 OVERVIEW This is B for the Catalyst tutorial. @@ -199,6 +200,15 @@ so allows us to have the same form submit the data to different actions (e.g., C for a create operation but C to update an existing book object). +B If you receive an error about Catalyst not being able to find +the template C, please verify that you followed the +instructions in the final section of +L where +you returned to a manually specified template. You can either use +C/C B default template names, but the two cannot +be used together. + + =head2 Update the CSS Edit C and add the following lines to the bottom of @@ -249,9 +259,9 @@ the bottom of the existing file:

HTML::Widget: Create - Update

+ =head2 Test The Create Form Press C to kill the previous server instance (if it's still @@ -540,7 +550,7 @@ match the following code: } # Set a status message for the user - $c->stash->{status_msg} = 'Book created'; + $c->flash->{status_msg} = 'Book created'; # Redisplay an empty form for another $c->stash->{widget_result} = $w->result; @@ -571,7 +581,7 @@ running) and restart it: $ script/myapp_server.pl -Try adding a book that validate. Return to the book list and the book +Try adding a book that validates. Return to the book list and the book you added should be visible. @@ -738,7 +748,7 @@ running) and restart it: $ script/myapp_server.pl -Try adding a book that validate. Return to the book list and the book +Try adding a book that validates. Return to the book list and the book you added should be visible. diff --git a/lib/Catalyst/Manual/Tutorial/Authentication.pod b/lib/Catalyst/Manual/Tutorial/Authentication.pod index bde0033..b330fd7 100644 --- a/lib/Catalyst/Manual/Tutorial/Authentication.pod +++ b/lib/Catalyst/Manual/Tutorial/Authentication.pod @@ -797,6 +797,71 @@ of this module on your system: perl -MCatalyst::Plugin::Authorization::ACL -e 'print $Catalyst::Plugin::Authorization::ACL::VERSION, "\n";' +=head1 USING THE SESSION FOR FLASH + +As discussed in Part 3 of the tutorial, C allows you to set +variables in a way that is very similar to C, but it will +remain set across multiple requests. Once the value is read, it +is cleared (unless reset). Although C has nothing to do with +authentication, it does leverage the same session plugins. Now that +those plugins are enabled, let's go back and improve the "delete +and redirect with query parameters" code seen at the end of the +C part of the tutorial. + +First, open C and modify C +to match the following: + + =head2 delete + + Delete a book + + =cut + + sub delete : Local { + # $id = primary key of book to delete + my ($self, $c, $id) = @_; + + # Search for the book and then delete it + $c->model('MyAppDB::Book')->search({id => $id})->delete_all; + + # Use 'flash' to save information across requests util it's read + $c->flash->{status_msg} = "Book deleted"; + + # Redirect the user back to the list page with status msg as an arg + $c->response->redirect($c->uri_for('/books/list')); + } + +Next, open C update the TT code to pull from flash +vs. the C query parameter: + + + +
+ [% status_msg || Catalyst.flash.status_msg %] + [% error_msg %] + [% content %] +
+ + + + +=head2 Try Out Flash + +Restart the development server and point your browser to +L to create an extra +book. Click the "Return to list" link and delete this "Test" book. +The C mechanism should retain our "Book deleted" status message +across the redirect. + +B While C will save information across multiple requests, +it does get cleared the first time it is read. In general, this is +exactly what you want -- the C message will get displayed on +the next screen where it's appropriate, but it won't "keep showing up" +after that first time (unless you reset it). Please refer to +L for additional +information. + + =head1 AUTHOR Kennedy Clark, C diff --git a/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod b/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod index b066395..75eb95e 100644 --- a/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod +++ b/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod @@ -206,11 +206,28 @@ in the development server log messages: INSERT INTO books (rating, title) VALUES (?, ?): `5', `TCPIP_Illustrated_Vol-2' INSERT INTO book_authors (author_id, book_id) VALUES (?, ?): `4', `6' + SELECT author.id, author.first_name, author.last_name + FROM book_authors me JOIN authors author + ON ( author.id = me.author_id ) WHERE ( me.book_id = ? ): '6' + +The C statements are obviously adding the book and linking it to +the existing record for Richard Stevens. The C