created in
L<Chapter 3|Catalyst::Manual::Tutorial::03_MoreCatalystBasics> to add
basic support for Create, Read, Update, and Delete (CRUD) of C<Book>
-objects. Note that the 'list' function in Chapter 3 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
+objects. Note that the 'list' function in
+L<Chapter 3|Catalyst::Manual::Tutorial::03_MoreCatalystBasics> 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
L<Chapter 9|Catalyst::Manual::Tutorial::09_AdvancedCRUD>.
Although this chapter of the tutorial will show you how to build CRUD
quick and easy. For example, see L<Catalyst::Plugin::AutoCRUD>,
L<CatalystX::CRUD>, and L<CatalystX::CRUD::YUI>.
-You can check out the source code for this example from the Catalyst
-Subversion repository as per the instructions in
+Source code for the tutorial in included in the F</root/Final> directory
+of the Tutorial Virtual machine (one subdirectory per chapter). There
+are also instructions for downloading the code in
L<Catalyst::Manual::Tutorial::01_Intro>.
header, and 2) the five lines for the Delete link near the bottom):
[% # This is a TT comment. -%]
-
+
[%- # Provide a title -%]
[% META title = 'Book List' -%]
-
+
[% # Note That the '-' at the beginning or end of TT code -%]
[% # "chomps" the whitespace/newline at that end of the -%]
[% # output (use View Source in browser to see the effect) -%]
-
+
[% # Some basic HTML with a loop to display books -%]
<table>
<tr><th>Title</th><th>Rating</th><th>Author(s)</th><th>Links</th></tr>
SELECT me.id, me.title, me.rating FROM book me WHERE ( ( me.id = ? ) ): '6'
DELETE FROM book WHERE ( id = ? ): '6'
- SELECT me.book_id, me.author_id FROM book_author me WHERE ( me.book_id = ? ): '6'
- DELETE FROM book_author WHERE ( author_id = ? AND book_id = ? ): '4', '6'
=head2 Fixing a Dangerous URL
Although the sample above only shows the C<content> div, leave the rest
of the file intact -- the only change we made to the C<wrapper.tt2> was
to add "C<|| c.request.params.status_msg>" to the
-C<E<lt>span class="message"E<gt>> line.
+C<E<lt>span class="message"E<gt>> line. Note that we definitely want
+the "C<| html>" TT filter here since it would be easy for users to
+modify the message on the URL and possibly inject harmful code into the
+application if we left that off.
=head2 Try the Delete and Redirect With Query Param Logic
sqlite> .quit
$
+Here are the commands without the surrounding sqlite3 prompt and output
+in case you want to cut and paste them as a single block (but still
+start sqlite3 before you paste these in):
+
+ ALTER TABLE book ADD created TIMESTAMP;
+ ALTER TABLE book ADD updated TIMESTAMP;
+ UPDATE book SET created = DATETIME('NOW'), updated = DATETIME('NOW');
+ SELECT * FROM book;
+
This will modify the C<books> table to include the two new fields and
populate those fields with the current time.
relationships we manually added below the "C<# DO NOT MODIFY...>" line
were automatically preserved.
-While we have this file open, let's update it with some additional
-information to have DBIC automatically handle the updating of these two
-fields for us. Insert the following code at the bottom of the file (it
-B<must> be B<below> the "C<# DO NOT MODIFY...>" line and B<above> the
-C<1;> on the last line):
+While we C<lib/MyApp/Schema/Result/Book.pm> open, let's update it with
+some additional information to have DBIC automatically handle the
+updating of these two fields for us. Insert the following code at the
+bottom of the file (it B<must> be B<below> the "C<# DO NOT MODIFY...>"
+line and B<above> the C<1;> on the last line):
#
# Enable automatic date handling
down.
+You can jump to the next chapter of the tutorial here:
+L<Authentication|Catalyst::Manual::Tutorial::05_Authentication>
+
+
=head1 AUTHOR
Kennedy Clark, C<hkclark@gmail.com>