Problem with paginator Pake Php

I ran into a knitting problem. I wrote code for pagination. Everything works as expected, but only the conditions do not work (only certain conditions) Here is my code for pagination.

//declaration 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( 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 works as a prefect in the development environment and returns logs that are of type 2, but in production they only return logs that are of type 1. I spent the whole day figuring out the problem. If I add some other condition to the conditions array , which will take effect, but not log_type . I print query logs, in where clause it always shows log_type = '1' I also cleared the cache. Any help appreciated, thanks.

+8
php cakephp pagination paginator
source share
2 answers

I have a problem fixed. This problem occurred due to the data type declared in the database. In production, this was tinyint(1) , and in development, int(1) . It stores the correct value in the database in both environments, but in tinyint(1) state it only works with 0 and 1, not 2.

I did not understand the reasons for this.

+2
source share

If your code works fine on the local computer but does not work during production, you need to clear all the files in tmp/cache/model and tmp/cahe/persistance . make sure you grant write permissions to the tmp folder.

This means that you need to update the Cake model schema when adding a new field, deleting an existing field, or making any changes to the database schema. In production mode If a schema cache file is not found, it will create new cache files based on the current schema in the database. In design mode, at each execution, it updates the schema cache.

Still its pagination problem, then you should follow the CakePHP 2.x documentation. Here, I assume your code is in ApiLogsController and the method is index . in accordance with the documentation should be your code.

 public function index() { $this->Paginator->settings = array( 'limit' => 50, 'order' => 'ApiLog.id DESC' 'paramType' => 'querystring', 'conditions'=> array('ApiLog.log_type' => 2), 'recursive'=>-1, // should be used with joins 'joins'=>array( array( 'table'=>'users', 'type'=>'LEFT', 'alias'=>'User', 'conditions'=>array('User.id = ApiLog.user_id') ) ) ); $data = $this->Paginator->paginate('ApiLog'); $this->set(compact('data')); } 

OR

 // your default setting in ApiLogController class public $components = array('Paginator'); public $paginate = array( 'limit' => 50, 'paramType' => 'querystring' ); public function index() { // overriding/extending default settings $this->Paginator->settings['order']='ApiLog.id DESC'; $this->Paginator->settings['conditions']=array('ApiLog.log_type' => 2), $this->Paginator->settings['recursive']= -1; $this->Paginator->settings['joins']=array( array( 'table'=>'users', 'type'=>'LEFT', 'alias'=>'User', 'conditions'=>array('User.id = ApiLog.user_id') ) ); $data = $this->Paginator->paginate('ApiLog'); $this->set(compact('data')); } 
+2
source share

All Articles