good morning community.
I am writing to you because I would like you to help me please with the following problem.
I have a search engine in my code made in cakephp to perform searches by customer, source address and destination address, when I try to add the code to perform search by id it throws me the following error:
Cannot convert value of type
string to integer
I share part of my code for a better understanding, I thank you in advance for your help
$q = $_REQUEST['q'];
$q = '%'.$q.'%';
$query = $query->where(['OR' => [
'id LIKE' => $q,
'Clients.name LIKE ' => $q,
'Deliveries.origin_address LIKE ' => $q,
'Deliveries.destination_address LIKE ' => $q
First of all: You should NEVER have the need to access superglobals like
$_REQUEST directly because you can easily use CakePHP to do much of the hard work for you.
$this->getRequest()->getQuery('q') to access
GET parameter or
$this->getRequest()->getData(); for e.g. POST data.
But anyway back to your problem:
My guess would be that you try to search a
string for integer columns, in your example the
do you really want to implement a search for IDs with
'id LIKE' => '%'.$q.'%', ?
So e.g. if you you search
23 you get results with ids
I personally would rather put that
id search in a separate input which can only be used as a number search instead of mixing up “fulltext” search with an “id search”
If you still want to do that you would have to parse the
$q into a string because everything coming from GET parameters is a
string, even if it is just
So you have to do a
$test = intval($q);
before you do your query to change the type of your