use warnings;
our $VERSION = "0.1";
__PACKAGE__->mk_classdata($_) for qw( _config init_done view_object );
-__PACKAGE__->mk_accessors ( qw( config ar params objects model_class
+__PACKAGE__->mk_accessors ( qw( config ar params query objects model_class
args action template ));
__PACKAGE__->config({});
__PACKAGE__->init_done(0);
$self->{args} = \@pi;
$self->{params} = { $self->{ar}->content };
+ $self->{query} = { $self->{ar}->args };
}
sub is_applicable {
sub view :Exported { }
sub edit :Exported { }
-sub list :Exported {
- my ($self, $r) = @_;
- $r->objects([ $self->retrieve_all ]);
-}
-
sub process {
my ($class, $r) = @_;
$r->template( my $method = $r->action );
=head2 Commands
-See the exported commands in C<Apache::MVC::Model::CDBI>.
+=over
+
+=item list
+
+The C<list> method should fill C<< $r-> objects >> with all of the
+objects in the class. You may want to page this using C<Data::Page> or
+similar.
+
+=back
+
+=cut
+
+sub list :Exported { die "This is an abstract method" };
+
+=pod
+
+Also, see the exported commands in C<Apache::MVC::Model::CDBI>.
=head1 Other overrides
use Class::DBI::AsForm;
use Class::DBI::FromCGI;
use Class::DBI::AbstractSearch;
+use Class::DBI::Pager;
use CGI::Untaint;
use strict;
+=head1 NAME
+
+Apache::MVC::Model::CDBI - Model class based on Class::DBI
+
+=head1 DESCRIPTION
+
+This is a master model class which uses C<Class::DBI> to do all the hard
+work of fetching rows and representing them as objects. It is a good
+model to copy if you're replacing it with other database abstraction
+modules.
+
+=cut
+
sub related {
my ($self, $r) = @_;
# Has-many methods; XXX this is a hack
$r->{template_args}{search} = 1;
}
+sub list :Exported {
+ my ($self, $r) = @_;
+ if ( my $rows = $r->config->{rows_per_page}) {
+ $self = $self->pager($rows, $r->query->{page});
+ $r->{template_args}{pager} = $self;
+ }
+ $r->objects([ $self->retrieve_all ]);
+}
1;
-=head1 NAME
-
-Apache::MVC::Model::CDBI - Model class based on Class::DBI
-
-=head1 DESCRIPTION
-
-This is a master model class which uses C<Class::DBI> to do all the hard
-work of fetching rows and representing them as objects; instead, it
-concentrates on the actions that can be performed in the URL:
-C<do_edit>, C<delete> and C<search>.
should be populated with the name of the table and the action parts of
the URL. Any other arguments should be placed in a listref in the
C<args> slot, and GET and POST parameters should be arranged into a hash
-and placed in the C<params> slot.
+and placed in the C<query> and C<params> slots, respectively.
Some people may not like the idea of passing everything around in the
URL; this is the method to override for you. Of course, you'll also need
#BeerDB->config->{uri_base} = "http://localhost/beerdb/";
BeerDB->config->{uri_base} = "http://neo.trinity-house.org.uk/beerdb/";
+BeerDB->config->{rows_per_page} = 10;
+
# Handpumps should not show up.
BeerDB->config->{display_tables} = [qw[beer brewery pub style]];
BeerDB::Brewery->untaint_columns( printable => [qw/name notes url/] );
"</tr>";
END %]
</TABLE>
+
+[% INCLUDE pager; %]
[% INCLUDE addnew; %]
</DIV>
--- /dev/null
+[%
+IF pager AND pager.first_page != pager.last_page;
+%]
+
+<P ALIGN="center">Pages:
+[%
+ FOREACH num = [pager.first_page .. pager.last_page];
+ IF num == pager.current_page;
+ "["; num; "] ";
+ ELSE;
+ '<A HREF="'; base; table; "/list/?page="; num; '">';
+ "["; num; "]";
+ '</A> ';
+ END;
+ END;
+%]
+</P>
+[% END %]