我正面临一个问题.我已经编写了分页代码.一切都按预期工作,但只有条件不起作用(只有特定条件)
这是我的分页代码.
这是我的分页代码.
//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');
此代码在开发环境和返回日志类型2上工作正常,但在生产中它只返回类型为1的日志.我花了一整天时间来找出问题.
如果我确实在条件数组中添加任何其他条件,该条件生效但不是log_type.
我打印查询日志,在where子句中它总是显示log_type =’1′
我也清除了缓存.
任何帮助表示感谢,谢谢.
如果您的代码在本地计算机上运行良好但在生产中不起作用,那么您必须清除tmp / cache / model和tmp / cahe / persistance中的所有文件.确保您已授予tmp文件夹的可写权限.
这意味着您必须在添加新字段,删除现有字段或在数据库架构中进行任何更改时更新Cake Model架构.在生产模式下如果未找到模式高速缓存文件,则它将基于数据库上的当前模式创建新的高速缓存文件.在每次执行的开发模式中,它将更新架构缓存.
仍然是它在分页中的问题,那么你必须遵循CakePHP 2.x文档.这里我假设您的代码在ApiLogsController中,方法是索引.根据您的代码应该是文档.
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')); }
要么
// 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','conditions'=>array('User.id = ApiLog.user_id') ) ); $data = $this->Paginator->paginate('ApiLog'); $this->set(compact('data')); }