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 Student.name 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()
->where([
'OR' => [
'enroll LIKE' => "%" . $query ."%",
'name LIKE' => "%" . $query . "%"
]
]);
I’m not sure how CakePHP 2.x treats this code but you should get the idea
Maybe someone else here has a better way of doing this, in which case, I’ll be glad to hear about it
2 Likes
Sometimes I use this plugin https://github.com/FriendsOfCake/search he do what you want… and let your code clean
1 Like
Thanks a lot I appreciate