X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FTutorial%2FBasicCRUD.pod;h=6c8e4308c6d2eece8e37a423c2b814127d7c5a82;hb=292eba91f41f6be26c6f432293a39b0ea938429d;hp=a6034c08688a01f6ea74957c074e6ebd3d92ac56;hpb=4d583dd846a0ffa9bd224014f89df39db957c35f;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod b/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod index a6034c0..6c8e430 100644 --- a/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod +++ b/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod @@ -1,14 +1,13 @@ =head1 NAME -Catalyst::Manual::Tutorial::BasicCRUD - Catalyst Tutorial – Part 3: Basic CRUD - +Catalyst::Manual::Tutorial::BasicCRUD - Catalyst Tutorial - Part 3: Basic CRUD =head1 OVERVIEW This is B for the Catalyst tutorial. -L +L =over 4 @@ -54,18 +53,28 @@ L =head1 DESCRIPTION -This part of the tutorial builds on the fairly primitive application created in Part 2 to add basic support for Create, Read, Update, and Delete (CRUD) of C objects. Note that the 'list' function in Part 2 already implements the Read portion of Crud (although Read normally refers to reading a single object; you could implement full read functionality using the techniques introduced below). This section will focus on the Create and Delete aspects of CRUD. More advanced capabilities, including full Update functionality, will be addressed in Part 8. - -B: Note that all of the code for this part of the tutorial can be pulled from the Catalyst Subversion repository in one step with the following command: +This part of the tutorial builds on the fairly primitive application +created in Part 2 to add basic support for Create, Read, Update, and +Delete (CRUD) of C objects. Note that the 'list' function in Part +2 already implements the Read portion of CRUD (although Read normally +refers to reading a single object; you could implement full read +functionality using the techniques introduced below). This section will +focus on the Create and Delete aspects of CRUD. More advanced +capabilities, including full Update functionality, will be addressed in +Part 8. - svn checkout http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial@### - IMPORTANT: Does not work yet. Will be completed for final version. +B: Note that all of the code for this part of the tutorial can be +pulled from the Catalyst Subversion repository in one step with the +following command: + svn checkout http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial -r 4611 . =head1 FORMLESS SUBMISSION -Our initial attempt at object creation will utilize the "URL arguments" feature of Catalyst (we will employ the more common form-based submission in the sections that follow). +Our initial attempt at object creation will utilize the "URL arguments" +feature of Catalyst (we will employ the more common form-based +submission in the sections that follow). =head2 Include a Create Action in the Books Controller @@ -74,21 +83,22 @@ Edit C and enter the following method: =head2 url_create - Create a book with the supplied title, rating and author + Create a book with the supplied title, rating, and author =cut sub url_create : Local { - # In addition to self & context, get the title, rating & author_id args - # from the URL. Note that Catalyst automatically puts extra information - # after the "///model('MyAppDB::Book')->create({ - title => $title, - rating => $rating + title => $title, + rating => $rating }); # Add a record to the join table for this book, mapping to @@ -112,7 +122,13 @@ Edit C and enter the following method: $c->stash->{template} = 'books/create_done.tt2'; } -Notice that Catalyst takes "extra slash-separated information" from the URL and passes it as arguments in C<@_>. The C action then uses a simple call to the DBIC C method to add the requested information to the database (with a separate call to C to update the join table). As do virtually all controller methods (at least the ones that directly handle user input), it then sets the template that should handle this request. +Notice that Catalyst takes "extra slash-separated information" from the +URL and passes it as arguments in C<@_>. The C action then +uses a simple call to the DBIC C method to add the requested +information to the database (with a separate call to +C to update the join table). As do virtually all +controller methods (at least the ones that directly handle user input), +it then sets the template that should handle this request. =head2 Include a Template for the C Action: @@ -124,55 +140,81 @@ Edit C and then enter: [% # optional, but prevents "massive indenting" of deeply nested objects -%] [% USE Dumper(Indent=1) -%] - [% # Set the page title -%] + [% # Set the page title. META can 'go back' and set values in templates -%] + [% # that have been processed 'before' this template (here it's for -%] + [% # root/lib/site/html and root/lib/site/header). Note that META on -%] + [% # simple strings (e.g., no variable interpolation). -%] [% META title = 'Book Created' %] [% # Output information about the record that was added. Note use -%] - [% # of 'first' to only list the first author (if > 1 author). -%] -

Added book '[% book.title %]' by '[% book.authors.first.last_name %]' + [% # of 'first' to only list the first author (if > 1 author). TT -%] + [% # v2.15 has an issue that requires -%] + [% # 'book.authors.list.first.value.last_name' vs. the shorter -%] + [% # 'book.authors.first.last_name' in prior versions. -%] +

Added book '[% book.title %]' + by '[% book.authors.list.first.value.last_name %]' with a rating of [% book.rating %].

[% # Provide a link back to the list page -%] [% # 'uri_for()' builds a full URI; e.g., 'http://localhost:3000/books/list' -%]

Return to list

- [% # Try out the TT Dumper -%] + [% # Try out the TT Dumper (for development only!) -%]
     Dump of the 'book' variable:
     [% Dumper.dump(book) %]
     
-The TT C directive allows access to a variety of plugin modules (we are talking TT plugins here, not Catalyst plugins) to add extra functionality to the base TT capabilities. Here, the plugin allows L "pretty printing" of objects and variables. Other than that, the rest of the code should be familiar from the examples in Part 2. - -B As mentioned earlier, the C view class created by TTSite redefines the name used to access the Catalyst context object in TT templates from the usual C to C. +The TT C directive allows access to a variety of plugin modules (TT +plugins, that is, not Catalyst plugins) to add extra functionality to +the base TT capabilities. Here, the plugin allows L +"pretty printing" of objects and variables. Other than that, the rest +of the code should be familiar from the examples in Part 2. +B As mentioned earlier, the C view +class created by TTSite redefines the name used to access the Catalyst +context object in TT templates from the usual C to C. =head2 Try the C Feature -If the application is still running from before, use C to kill it. Then restart the server: +If the application is still running from before, use C to kill +it. Then restart the server: $ script/myapp_server.pl -Note that new path for C appears in the startup debug output. +Note that new path for C appears in the startup debug +output. -B: You can use C