CakePHP order not working

后端 未结 3 1801
清酒与你
清酒与你 2021-01-20 00:28

Hi i am using CakePHP version - 2.5.5.

I have a table name chat_ategory_mages I want to get Average number of Frequency Order by Descending. Know about

相关标签:
3条回答
  • 2021-01-20 00:42

    This happened to me to. You have to add to the paginate function the third parameter $whitelist. For example.

    $this->Paginator->settings = array(
            'conditions'=>array('ChatCategoryImage.chat_category_id'=>$cetegory_id),
            'fields'=>$fields,
            'limit' => 10,
            'order' => $order,
    );
    $scope =  array();
    $whitelist = array('ChatCategoryImage.id', ...); //The fields you want to allow ordering.
    
    $getCategoryImages = $this->Paginator->paginate('ChatCategoryImage', $scope, $whitelist);
    pr($getCategoryImages);
    

    I do not know why this is happening. I tried to see the code inside the paginate function but i could not figure it out.

    0 讨论(0)
  • 2021-01-20 00:55

    Your code was lil wrong

        $this->paginate = array(
                       'conditions' => array('ChatCategoryImage.chat_category_id'=>$cetegory_id), 
                       'limit' => 10, 'order' => 'Frequency' => 'DESC');
        $getAllCourses = $this->paginate('ChatCategoryImage');
    
    0 讨论(0)
  • 2021-01-20 01:01

    You can use virtualFields

    $this->ChatCategoryImage->virtualFields = array('Frequency' => 'hits/(DATEDIFF(NOW(),created))');
    

    changing the way of order

    $order = array('Frequency' => 'desc');
    
    0 讨论(0)
提交回复
热议问题