I'm new to CakePHP and trying to implement the FriendsOfCake Search plugin found here: https://github.com/FriendsOfCake/search
For starters I'm just trying to implement a basic search on the Users table, and I feel I'm pretty close to having it, but for whatever reason it isn't working. I've followed the Usage guide from the link above, but modifying it for my model. I'll include the snippets of code I've used, and indicate changes:
In my Users Table class I've used the following code:
public function searchConfiguration()
{
$search = new Manager($this);
$search->value('first_name', [
'field' => $this->aliasField('first_name')
])
->like('q', [
'before' => true,
'after' => true,
'field' => [$this->aliasField('first_name')]
]);
return $search;
}
For the basic search I'm wanting to implement just a search on First Name only. I'll add more once it's up and running.
In my Users Controller, I've modified the search code in my index method to this:
$query = $this->Users->find('search', $this->Users->filterParams($this->request->query))->where(['first_name != ' => null ]);
$this->set('users', $this->paginate($query));
$this->set('_serialize', ['users']);
At this point if I load my Users list page, it's returning 0 results. The usage guide indicates that I should be able to run queries by adding ?q=John to the end of the url to get a list of users which include John in their name, but I'm coming up with an empty result set. If I modify the where statement to be where(['first_name != \'John\''] it will query my Users table and return only John records, so I'm assuming something isn't passing the correct parameters to my query. From what I can tell, the Usage guide indicates that running this without a parameter should result in a list of all records that are not NULL.
Can anyone help point me in the right direction? I'm unable to find anything else that shows a usage guide for the Search plugin I'm trying to use.
For reference this app us using CakePHP version 3.1.0
I'm also new to using StackOverflow, so if I've done some incorrectly here, let me know and I'll add or edit whatever else I need.
Thanks!