引导程序:
Route::set('user', 'user/<username>(/<action>)')
->defaults(array(
'controller' => 'user',
'username' => '\d+',
));
控制器用户:
public function action_cget(){
$page_num = @$_GET['page']? $_GET['page'] : 1;
$per_page = 5;
$offset = ($page_num - 1) * $per_page;
$username = $this->request->param('username');
$session = Session::instance();
$mUser = Model::factory('User');
$id = $mUser->getID($username);
$view = View::factory('index');
$total = DB::query(Database::SELECT, 'SELECT * FROM `comments` WHERE `post_id` IN('.$ids.')')->execute()->as_array();
$q = DB::query(Database::SELECT, 'SELECT * FROM `comments` WHERE `post_id` IN('.$ids.') LIMIT '.$per_page.' OFFSET '.$offset)->execute()->as_array();
$pagination = Pagination::factory(array(
'total_items' => count($total),
'current_page' => array('source' => 'query_string', 'key' => 'page'),
'items_per_page' => $per_page,
'view' => 'pagination/basic'));
$view->content = View::factory('user/cget');
$view->content->comments = $q;
$view->content->pagi = $pagination;
$this->response->body($view);
(我删除了更多代码)
一切都很好,但分页渲染不好 - 渲染没有动作。
我在页面http://mysite.com/user/NetJaro/cget
和分页呈现链接,如http://mysite.com/user/NetJaro?page=2(没有操作,如“cget”)。
有人可以帮助我吗?:)
谢谢!