If you are using version 3.x of CakePHP it can be done this way:
$user_email = $this->request->data('user_email');
$this->User->find('all', [
'conditions' => [
'OR' => [
'User.name LIKE' => '%'.$user_email.'%',
'User.email LIKE' => '%'.$user_email.'%',
]
]
]);
I think it works also in version 2.x.
Edited:
Adding content to the response:
Looking at your answer, I tried to apply it to the filter, doing this:
<?php
$this->FilterResults->addFilters(
array(
'filter1' => array(
'OR' => array(
'User.name' => array(
'operator' => 'ILIKE',
'value' => array(
'before' => '%',
'after' => '%'
)
),
'User.username' => array(
'operator' => 'ILIKE',
'value' => array(
'before' => '%',
'after' => '%'
)
)
)
)
)
);
With this filter if I debug the same, I will have the following output:
debug($this->Filter->getConditions());
die();
saída:
------
array(
'OR' => array(
'User.nome ILIKE' => '%valordigitado%',
'User.username ILIKE' => '%valordigitado%'
)
)
Then I go through these conditions and check that $chave == 'OR'
is the result of the applied filter, so I assign its value to the filter variable as below:
$conditions = array();
$filter1 = '';
foreach ($this->Filter->getConditions() as $chave => $valor) {
if ($chave == 'OR') {
$filter1 = $valor;
}
}
After assigning a variable the value that was typed in the field:
$nome_username = $this->request->data['filter']['filter1'];
Then I check if the variable $filter1
is empty and I apply the condition to put in Paginator
if (!empty($filter1)) {
$conditions[] = "(User.nome ILIKE '%$nome_username%'
OR User.username ILIKE '%$nome_username%')";
}
And in Paginator
I apply the variable $conditions
like this:
$this->Paginator->settings = array(
'fields' => array( XXXXXX ),
'joins' => array( XXXXXXX ),
'conditions' => array($conditions)
);