1 package Apache::MVC::Model::CDBI;
2 use base qw(Apache::MVC::Model::Base Class::DBI);
3 use Class::DBI::AsForm;
4 use Class::DBI::FromCGI;
7 sub description { "A poorly defined class" }
9 sub column_names { my $class = shift; map { $_ => ucfirst $_ } $class->columns }
13 return $self->retrieve(shift @{$r->{args}});
16 sub do_edit :Exported {
18 my $h = CGI::Untaint->new(%{$r->{params}});
19 my ($obj) = @{$self->objects};
21 # We have something to edit
22 $obj->update_from_cgi($h);
23 warn "Updating an object ($obj) with ".Dumper($h); use Data::Dumper;
25 $obj = $self->create_from_cgi($h);
27 if (my %errors = $obj->cgi_update_errors) {
28 # Set it up as it was:
29 warn "There were errors: ".Dumper(\%errors)."\n";
30 $r->{template_args}{cgi_params} = \%params;
31 $r->{template_args}{errors} = \%errors;
32 $r->{template} = "edit";
34 $r->{template} = "view";
36 $r->objects([ $obj ]);
39 sub delete :Exported {
41 $_->SUPER::delete for @{ $r->objects };
42 $r->objects([ $self->retrieve_all ]);
43 $r->{template} = "list";
47 my ($self, $child) = @_;
48 $child->autoupdate(1);
49 $child->columns( Stringify => qw/ name / );