Working with an array of search parameters


#1

Hi!

I have a search form where user may search by one or a combo of these
items:
Last Name
First Name
Alias Last Name
Alias First Name
Case Number

First of all, how do I set up the fields in _form to return an array
to the controller?

Secondly, how do I access the array in the controller and generate an
appropriate “find” statement based on what array elements were passed
in?

As it stands now, I’m setting each parameter to a variable and then in
a giant “if” statement constructing the “find” statement. This worked
ok with just name and case number to search for. Now that I’ve added
alias to the mix, this is turning into some majorly UGLY code. Too
many possible combinations!

Any thoughts/suggestions/ideas are welcomed and appreciated.

Thank you!! ~Ali


#2

you can use the criteria_query plugin to make life a little easier:
http://agilewebdevelopment.com/plugins/criteria_query

I tried using it myself, but ended up falling back on multiple if
statements and building the conditions string and params array by
hand, since in pretty much every case, I need paginate my result set,
which criteria query won’t let you do.

Here’s some example code from my search action in one of my
controllers, to show you my approach:

http://pastie.caboo.se/84234

I stored each search parameter into an ivar so when the page is
redisplayed, the search terms will still be filled out in my search
form…

Adam