如何从CAKEPHP2.x中的自定义分页中对数据进行排序?

时间:2015-10-12 22:16:05

标签: php cakephp pagination

我收到今天的数据:

public function index() {
    $this->Apertura->recursive = 0;
    $now = new DateTime();
    $options = array('conditions' => array('Apertura.created >= ' => $now->format('Y-m-d 00:00:00')));  
    $this->set('aperturas',
        $this->Apertura->find('all', $options),
        $this->Paginator->paginate('Apertura', array('Apertura.created >= ' => $now->format('Y-m-d 00:00:00'))));
}

但是当我把一个标题栏引用时,我无法对表格进行排序:

        <th><?php echo $this->Paginator->sort('id',"ID"); ?></th>
        <th><?php echo $this->Paginator->sort('Vendedore.nombre',"Vendedor"); ?></th>
        <th><?php echo $this->Paginator->sort('vehiculo_id',"Vehículo"); ?></th>
        <th><?php echo $this->Paginator->sort('observaciones',"Observaciones"); ?></th>
        <th><?php echo $this->Paginator->sort('created',"Hora y fecha"); ?></th>

如果我删除条件和自定义 Paginate ,我可以对表格进行排序。发生了什么事?

1 个答案:

答案 0 :(得分:0)

是的,解决方案是:

public function index() {
    $this->Apertura->recursive = 0;
    $now = new DateTime();
    $this->Paginator->settings = array(
        'conditions' => array('Apertura.created >= ' => $now->format('Y-m-d 00:00:00')),
        'limit' => 10
    );

    $data = $this->Paginator->paginate('Apertura');

    $this->set('aperturas',$data);
}