[Catalyst-commits] r9388 -
Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial
hkclark at dev.catalyst.perl.org
hkclark at dev.catalyst.perl.org
Mon Feb 23 22:39:17 GMT 2009
Author: hkclark
Date: 2009-02-23 22:39:17 +0000 (Mon, 23 Feb 2009)
New Revision: 9388
Modified:
Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod
Log:
Improve use of uri_for() to use action_for()
Modified: Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod
===================================================================
--- Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod 2009-02-23 22:07:30 UTC (rev 9387)
+++ Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod 2009-02-23 22:39:17 UTC (rev 9388)
@@ -620,7 +620,7 @@
</td>
<td>
[% # Add a link to delete a book %]
- <a href="[% c.uri_for('id', book.id, 'delete') %]">Delete</a>
+ <a href="[% c.uri_for(c.controller.action_for('delete'), [ book.id ]) %]">Delete</a>
</td>
</tr>
[% END -%]
@@ -630,6 +630,14 @@
right side of the table with a C<Delete> "button" (for simplicity,
links will be used instead of full HTML buttons).
+Also notice that we are using a more advanced form of C<uri_for> than
+we have seen before. Here we use C<$c-E<gt>controller-E<gt>action_for>
+to automatically generate a URI appropriate for that action while
+inserting the C<book.id> value into the appropriate place. Now, if
+you ever change C<:PathPart('delete')> in your controller method to
+C<:PathPart('kill')>, then your links will automatically update without
+any changes to your .tt2 template file.
+
B<Note:> You should use more than just a simple link with your
applications. Consider using some sort of of confirmation page
(typically with unique actions in your controller for both the
@@ -806,7 +814,7 @@
$c->stash->{status_msg} = "Book deleted.";
# Redirect the user back to the list page
- $c->response->redirect($c->uri_for('/books/list'));
+ $c->response->redirect($c->uri_for($c->controller->action_for('list'));
}
@@ -848,7 +856,7 @@
$c->stash->{object}->delete;
# Redirect the user back to the list page with status msg as an arg
- $c->response->redirect($c->uri_for('/books/list',
+ $c->response->redirect($c->uri_for($c->controller->action_for('list'),
{status_msg => "Book deleted."}));
}
More information about the Catalyst-commits
mailing list