1 package Apache::MVC::Model::CDBI;
2 use base 'Apache::MVC::Model::Base';
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}});
21 # We have something to edit
22 ($obj) = @{$self->objects};
23 $obj->update_from_cgi($h);
24 warn "Updating an object ($obj) with ".Dumper($h); use Data::Dumper;
26 $obj = $self->create_from_cgi($h);
28 if (my %errors = $obj->cgi_update_errors) {
29 # Set it up as it was:
30 warn "There were errors: ".Dumper(\%errors)."\n";
31 $r->{template_args}{cgi_params} = \%params;
32 $r->{template_args}{errors} = \%errors;
33 $r->{template} = "edit";
35 $r->{template} = "view";
40 sub delete :Exported {
42 $self->delete for @{ $r->objects };
43 $r->objects([ $self->retrieve_all ]);
44 $r->{template} = "list";
48 my ($self, $child) = @_;
49 $child->autoupdate(1);
50 $child->columns( Stringify => qw/ name / );