Karan Karan - 1 year ago 68
PHP Question

Cake Php paginator issue

I am facing a weired issue. I have written code for pagination. Everything is working as expected, but only conditions are not working(only certain conditions)
Here is my code for pagination.

public $paginate = array(
'limit' => 50,
'paramType' => 'querystring'
//use in action
$this->paginate['ApiLog'] = array('limit' => 50, 'order' => 'ApiLog.id DESC', 'paramType' => 'querystring');

$this->paginate['ApiLog']['conditions'] = array('ApiLog.log_type' => 2);
$this->paginate['ApiLog']['joins'] = array(
'table' => 'users',
'alias' => 'User',
'type' => 'LEFT',
'conditions' => array('User.id = ApiLog.user_id')
$this->Paginator->settings = $this->paginate['ApiLog'];
$apilogs = $this->Paginator->paginate('ApiLog');

This code is working prefect on development environment and return logs that has type 2, but in production it return only logs that has type 1. I have spent whole day to figure out issue.
If i do add any other condition in
conditions array
that does take effect but not
I print Query logs, in
where clause
it always show
log_type = '1'

I have cleared cache as well.
Any help appreciated, thanks.

Answer Source

I have fixed issue, This issue was due to data type declared into database. In production it was tinyint(1) and in development it given int(1). It is saving correct value in database in both environment but in condition tinyint(1) is working with only 0 & 1 not with 2.

I didn't understand reason behind this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download