Cakephp search form

Hi guys please i need some help, i have a search field code below it can search with students enroll number but i also want to search with student name also how can i add, if i change the Student.enroll to it search with name and if i change it to Student.enroll it will search with enroll number but i want to search with both either with enroll number or name

public $filterArgs = array(‘keyword’ => array(‘type’ => ‘like’,‘field’=>‘Student.enroll’));

In 3.x one can accomplish it like this:

$result = $this->Students-find()
    'OR' => [
      'enroll LIKE' => "%" . $query ."%",
      'name LIKE' => "%" . $query . "%"

I’m not sure how CakePHP 2.x treats this code but you should get the idea :slight_smile:
Maybe someone else here has a better way of doing this, in which case, I’ll be glad to hear about it :slight_smile:


Sometimes I use this plugin he do what you want… and let your code clean :wink:

1 Like

Thanks a lot I appreciate