Monday, December 29, 2008

Searh On Multiple Fields

Since I can't get Ferret working on my ubuntu, here's my solution to search on multiple fields

Well CakePHP find is way much cooler from RoR


def index
if params[:term]
@employees = Employee.find(:all,
:conditions => ['first_name LIKE ? OR
last_name LIKE ? OR
email LIKE ? OR
mobile_number LIKE ? OR
description LIKE ? ', "%#{params[:term]}%",
"%#{params[:term]}%",
"%#{params[:term]}%",
"%#{params[:term]}%",
"%#{params[:term]}%"])
else
@employees = Employee.find(:all)
end

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @employees }
end
end

No comments:

Post a Comment