X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FTutorial%2F04_BasicCRUD.pod;h=4a703f1bc397f98a3c5b2d61ed2a5c11707e1139;hb=ee53cc71ffd9f722718589c60447379843a90682;hp=3e7e02ebe5ceac136b31c7ec36ef0f5d839cf16e;hpb=fce83e5f2a2da9f9117562d05aec1e161cc3c109;p=catagits%2FCatalyst-Manual.git diff --git a/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod b/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod index 3e7e02e..4a703f1 100644 --- a/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod +++ b/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod @@ -56,34 +56,32 @@ L =head1 DESCRIPTION -This chapter of the tutorial builds on the fairly primitive -application created in Chapter 3 to add basic support for Create, -Read, Update, and Delete (CRUD) of C objects. Note that the -'list' function in Chapter 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 Chapter 9. - -Although this chapter of the tutorial will show you how to build CRUD -functionality yourself, another option is to use a "CRUD builder" type -of tool to automate the process. You get less control, but it's quick -and easy. For example, see -L, -L, and -L. +This chapter of the tutorial builds on the fairly primitive application +created in Chapter 3 to add basic support for Create, Read, Update, and +Delete (CRUD) of C objects. Note that the 'list' function in +Chapter 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 +Chapter 9. + +Although this chapter of the tutorial will show you how to build CRUD +functionality yourself, another option is to use a "CRUD builder" type +of tool to automate the process. You get less control, but it can be +quick and easy. For example, see L, +L, and L. You can check out the source code for this example from the Catalyst Subversion repository as per the instructions in -L. +L. =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 @@ -96,7 +94,7 @@ Edit C and enter the following method: =cut - sub url_create : Local { + 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 "// and enter the following method: # Note: Above is a shortcut for this: # $book->create_related('book_authors', {author_id => $author_id}); - # Assign the Book object to the stash for display in the view - $c->stash->{book} = $book; - - # Set the TT template to use - $c->stash->{template} = 'books/create_done.tt2'; + # Assign the Book object to the stash for display and set template + $c->stash(book => $book, + template => 'books/create_done.tt2'); } Notice that Catalyst takes "extra slash-separated information" from the @@ -167,47 +163,38 @@ Edit C and then enter: [% Dumper.dump(book) %] -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 Chapter 3. +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 Chapter 3. -Note: If you are using TT v2.15 you will need to change the code that +Note: If you are using TT v2.15 you will need to change the code that outputs the "last name for the first author" above to match this: [% authors = book.authors %] by '[% authors.first.last_name IF authors.first; authors.list.first.value.last_name IF ! authors.first %]' -to get around an issue in TT v2.15 where blessed hash objects were not -handled correctly. But, if you are still using v2.15, it's probably -time to upgrade (v2.15 is exactly 3 years old on the day I'm typing -this). If you are following along in Debian, then you should be on at -least v2.20. You can test your version of Template Toolkit with the -following: +to get around an issue in TT v2.15 where blessed hash objects were not +handled correctly. But, if you are still using v2.15, it's probably +time to upgrade (v2.15 is almost 4 years old). If you are following +along in Debian, then you should be on at least v2.20. You can test +your version of Template Toolkit with the following: perl -MTemplate -e 'print "$Template::VERSION\n"' =head2 Try the 'url_create' Feature -If the application is still running from before, use C to kill -it. Then restart the server: +Make sure the development server is running with the "-r" restart +option: - $ DBIC_TRACE=1 script/myapp_server.pl + $ DBIC_TRACE=1 script/myapp_server.pl -r Note that new path for C appears in the startup debug output. -B: You can use C