O'Reilly logo

Catalyst 5.8 by Antano Solar John

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Basic CRUD

Let's start by writing the easiest method, a method to delete a person from the database. All we need is a simple action in the Person Controller. (Note: The order of the methods in the Person.pm file does not matter. You can add this method before or after sub index{ }):

sub delete : Local {
my ($self, $c, $id) = @_;
my $person = $c->model('AddressDB::People')->
find({id => $id});
$c->stash->{person} = $person;
if($person){
$c->stash->{message} = 'Deleted '. $person->name;
$person->delete;
}
else {
$c->response->status(404);
$c->stash->{error} = "No person $id";
}
$c->forward('list');
}

This action will create a URL that looks like /person/delete/1, where 1 is the person's ID number in the database. Using that ID number that's passed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required