From 7afc363f8b7cd7b710d4ee4199976165363bcfab Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Sat, 31 Jan 2004 15:48:36 +0000 Subject: [PATCH] This adds basic searching. Want to change it to AbstractSearch, though. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@32 48953598-375a-da11-a14b-00016c27c3ee --- lib/Apache/MVC/Model/CDBI.pm | 14 +++++++++++++- templates/factory/list | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Apache/MVC/Model/CDBI.pm b/lib/Apache/MVC/Model/CDBI.pm index 695e1cb..88c1d52 100644 --- a/lib/Apache/MVC/Model/CDBI.pm +++ b/lib/Apache/MVC/Model/CDBI.pm @@ -4,6 +4,7 @@ use Lingua::EN::Inflect::Number qw(to_PL); use Class::DBI::AsForm; use Class::DBI::FromCGI; use CGI::Untaint; +use strict; sub description { "A poorly defined class" } @@ -37,7 +38,7 @@ sub do_edit :Exported { if (my %errors = $obj->cgi_update_errors) { # Set it up as it was: warn "There were errors: ".Dumper(\%errors)."\n"; - $r->{template_args}{cgi_params} = \%params; + $r->{template_args}{cgi_params} = $r->{params}; $r->{template_args}{errors} = \%errors; $r->{template} = "edit"; } else { @@ -59,4 +60,15 @@ sub adopt { $child->columns( Stringify => qw/ name / ); } +sub search :Exported { + my ($self, $r) = @_; + my %fields = map {$_ => 1 } $self->columns; + my %values = map { $_ => $params{$_} } + grep { $params{$_} and $fields{$_} } keys %{$r->{params}}; + $r->objects([ %values ? $self->search_like(%values) : $self->retrieve_all ]); + $r->template("list"); + $r->{template_args}{search} = 1; +} + + 1; diff --git a/templates/factory/list b/templates/factory/list index efd3a95..d52d3e8 100644 --- a/templates/factory/list +++ b/templates/factory/list @@ -2,7 +2,11 @@ [% INCLUDE header %] +[% IF search %] +

Search results

+[% ELSE %]

Listing of all [% classmetadata.plural %]

+[% END %] [% INCLUDE navbar %] -- 2.39.5