# Create a new book
my $book = $c->model('DB::Books')->new_result({});
# Save the form data for the book
- $form->save_to_model($book);
+ $form->model->update($book);
# Set a status message for the user
$c->flash->{status_msg} = 'Book created';
# Return to the books list
- $c->response->redirect($c->uri_for('list'));
+ $c->response->redirect($c->uri_for($self->action_for('list')));
$c->detach;
} else {
# Get the authors from the DB
[%# Render the HTML::FormFu Form %]
[% form %]
- <p><a href="[% c.uri_for('list') %]">Return to book list</a></p>
+ <p><a href="[% c.uri_for(c.controller.action_for('list')) %]">Return to book list</a></p>
=head2 Add Links for Create and Update via C<HTML::FormFu>
<p>
HTML::FormFu:
- <a href="[% c.uri_for('formfu_create') %]">Create</a>
+ <a href="[% c.uri_for(c.controller.action_for('formfu_create')) %]">Create</a>
</p>
This adds a new link to the bottom of the book list page that we can
# Make sure we were able to get a book
unless ($book) {
$c->flash->{error_msg} = "Invalid book -- Cannot edit";
- $c->response->redirect($c->uri_for('list'));
+ $c->response->redirect($c->uri_for($self->action_for('list')));
$c->detach;
}
# is shorthand for "$form->submitted && !$form->has_errors"
if ($form->submitted_and_valid) {
# Save the form data for the book
- $form->save_to_model($book);
+ $form->model->update($book);
# Set a status message for the user
$c->flash->{status_msg} = 'Book edited';
# Return to the books list
- $c->response->redirect($c->uri_for('list'));
+ $c->response->redirect($c->uri_for($self->action_for('list')));
$c->detach;
} else {
# Get the authors from the DB
# Add the authors to it
$select->options(\@authors);
# Populate the form with existing values from DB
- $form->defaults_from_model($book);
+ $form->model->default_values($book);
}
# Set the template
=item *
If the form has been submitted and passes validation, we skip creating a
-new book and just use C<$form-E<gt>save_to_model> to update the existing
+new book and just use C<$form-E<gt>model-E<gt>update> to update the existing
book.
=item *
If the form is being displayed for the first time (or has failed
validation and it being redisplayed), we use
- C<$form-E<gt>default_from_model> to populate the form with data from the
+ C<$form-E<gt>model-E<gt>default_values> to populate the form with data from the
database.
=back
...
<td>
[% # Add a link to delete a book %]
- <a href="[% c.uri_for('delete', book.id) %]">Delete</a>
+ <a href="[% c.uri_for(c.controller.action_for('delete', [book.id])) %]">Delete</a>
[% # Add a link to edit a book %]
- <a href="[% c.uri_for('formfu_edit', book.id) %]">Edit</a>
+ <a href="[% c.uri_for(c.controller.action_for('formfu_edit', [book.id])) %]">Edit</a>
</td>
...
be returned to the book list with a "Book edited" message at the top in
green. Experiment with other edits to various books.
+=head2 More Things to Try
+
+You are now armed with enough knowledge to be dangerous. You can keep
+tweaking the example application; some things you might want to do:
+
+=over 4
+
+=item *
+
+Add an appropriate ACL to the new Edit function.
+
+=item *
+
+Cleanup the List page so that the Login link only displays when the user
+isn't logged in and the Logout link only displays when a user is logged
+in.
+
+=item *
+
+Add a more sensible policy for when and how users and admins can do
+things in the CRUD cycle.
+
+=item *
+
+Support the CRUD cycle for authors.
+
+=back
+
+Or you can proceed to write your own application, which is probably the
+real reason you worked through this Tutorial in the first place.
=head2 Config::General Config for this tutorial