Perl Catalyst search function to search multiple columns -
i have table in sqlite database , have schema called account. have form searches users. in controller this:
my $params ||= $c->req->parameters; # don't know difference between ||= , =, did way because had done , works $search_term = $params->{search}; if( $c->request->params{submit} ) { $c->stash->{search_term} = $search_term; $c->stash->{search_results} = $c->model("db::account")->find({ firstname => { => "%$search_term%" }, }) if $c->stash->{search_term}; } then in view have this.
[% if search_results > 0 %] [% foreach results in search_results %] [% results.email %] <br/> [% results.firstname %] [% end %] the above code works fine. want search table matching firstname, lastname or other columns, instead of 1 column.
i new catalyst framework , perl (had done stuff perl, not advanced), , tips appreciated.
as this:
my $params ||= $c->req->parameters; the same as:
my $params = $params || $c->req->parameters; # when $params not defined # used part after || as searching row table. method find find 1 row.
$c->stash->{search_results} = $c->model("db::account")->find({ firstname => { => "%$search_term%" }, }); in order find rows should use methods search or search_rs. this:
$c->stash->{search_results} = $c->model("db::account")->search({ firstname => { => "%$search_term%" }, lastname => "smith", email => "jsmith@abc.de" }) that's all! more info have read dbix::class::resultset
upd
in order view result in tt file should use this:
[% while (row = search_results.next) %] [% row.email %] [% row.firstname %] [% end %]
Comments
Post a Comment