Php – simple Search in cakephp 2.0

cakephpPHPsearch

I am trying to build a simple phonebook in cakephp 2.0 that stores & retrieves information.

currently i have a table named contacts, with the following fields in it.
– Name
– Phone no.
– email
– Location

I would like to integrate a simple search feature that lists contacts matching to the query. since its a very basic simple app, I wanna keep this as simple as possible.

any suggestions?

Best Answer

<?php
$keyword=$this->params->query['keyword']; //get keyword from querystring//
//used simpme or condition with singe value checking
//replace ModelName with actual name of your Appmodel
$cond=array('OR'=>array("ModelName.phone LIKE '%$keyword%'","ModelName.name LIKE '%$keyword%'", "ModelName.email LIKE '%$keyword%'")  );

$list = $this->ModelName->find('all',array('conditions')=>$cond);


?>
Related Topic