CakePHP中使用Paginator组件(Helper)实现表格的翻页及排序

参考网页:http://abcoder.com/php/cakephp/cakephp-advanced-pagination-sort-by-derived-field/

实现起来很简单,直接看代码吧:

 

works_controller.php

<?php class WorksController extends AppController { var $helpers = array('Html', 'Form', 'Paginator'); var $name = 'Works'; public function index() { $thismonth = date("Y-m", time()); $this->paginate = array( 'conditions' => array('Work.adate like' => $thismonth . '%'), 'order' => array('Work.adate' => 'asc'), 'limit' => '10', 'page' => '1' ); $works = $this->paginate('Work'); $this->set(compact('works')); // $this->set('works', $this->Work->find('all', array('conditions' => array('Work.adate like' => $thismonth . '%')))); } }

 

index.ctp

<?php echo $paginator->first('First') . '  '; echo $paginator->prev('Previous'). '  '; echo $paginator->numbers(). '  '; echo $paginator->next('Next'). '  '; echo $paginator->last('Last'). '  '; ?> <table> <tr> <th><?php echo $paginator->sort('日付', 'adate'); ?></th> <th><?php echo $paginator->sort('作業開始', 'btime'); ?></th> <th><?php echo $paginator->sort('作業終了', 'ctime'); ?></th> <th><?php echo $paginator->sort('作業内容', 'content'); ?></th> <th> </th> <th> </th> <th> </th> </tr> <?php foreach ($works as $work): ?> <tr> <td width="100px"><?php echo $work['Work']['adate']; ?></td> <td width="80px"><?php echo $work['Work']['btime']; ?></td> <td width="80px"><?php echo $work['Work']['ctime']; ?></td> <td><?php echo $work['Work']['content']; ?></td> <td width="40px"><?php echo $this->Html->link("閲覧", array('controller' => 'works', 'action' => 'select', $work['Work']['id'])); ?></td> <td width="40px"><?php echo $this->Html->link("編集", array('controller' => 'works', 'action' => 'update', $work['Work']['id'])); ?></td> <td width="40px"><?php echo $this->Html->link("削除", array('controller' => 'works', 'action' => 'delete', $work['Work']['id']), null, '該当データを削除したい?'); ?></td> </tr> <?php endforeach; ?> </table>

 

时下很多项目使用结合JS脚本组件实现翻页及排序,例如:http://www.imwls.com/the-most-jquery-table-plugins

当然也未尝不可,呵呵。

你可能感兴趣的:(Date,function,脚本,delete,action,cakephp)