gleez 下分页功能优化

gleez 下分页功能优化

 

当一个控制器里的方法只调用了一次分页功能,且在index的方法里,则无需进行以下优化,否则可以根据建议内容优化;


找到/modules/gleez/classes/gleez/pagination.php文件下的url方法;修改内容见红色字体


public function url($page = 1)

{

// Clean the page number

$page = max(1, (int) $page);

 

// gleez cms pagination

$pager = '/p'. $page;


// No page number in URLs to first page

if ($page === 1 AND ! $this->config['first_page_in_url'])

{

$page = NULL;

$pager = NULL;

}

 

switch ($this->config['current_page']['source'])

{

case 'query_string':

 

//return URL::site($this->_route->uri($this->_route_params).

// $this->query(array($this->config['current_page']['key'] => $page)));

//当调用分页功能时,带uri传值时,则在url链接直接增加查询页数;否则显示的url默认指向该控制器的index的方法,后增加查询页数(且url省略index方法名显示)

if($this->_uri){

return URL::site($this->_uri.

$this->query(array($this->config['current_page']['key'] => $page)));

}else{

return URL::site($this->_route->uri($this->_route_params).

$this->query(array($this->config['current_page']['key'] => $page)));

}



case 'route':

return URL::site($this->_route->uri(

array_merge(

$this->_route_params,

array($this->config['current_page']['key'] => $page)

)

). $this->query());

case 'cms':

return URL::site($this->_uri . $pager . $this->query());

}


return '#';

}


在控制器方法里调用分页功能的方法,写法如下:

public function action_select()

{

$this->title = __(‘分页测试’);

$sql_p = “SELECT * FROM products”;

$p_values = DB::query(Database::SELECT,$sql_p)

          ->execute()

           ->as_array();

   //计算总的查询记录

    $count = count($p_values );

   //分页

    $pagination = Pagination::factory(array(

      'items_per_page' =>20,

     'total_items' => $count,

      'uri' => $this->request->uri(),//优化分页功能后,新增的

   ));


   $current_page = isset($_GET['page'])?$_GET['page']:1;

   $sql_p     .=" LIMIT ".(($current_page-1)*20).",20";

   $p_values  = DB::query(Database::SELECT,$sql_p )

     ->execute()

     ->as_array();

//加载试图

$view = View::factory('fenye')

           ->bind("pagination",$pagination)

->bind(“p_values”,$values);

        $this->response->body($view);

}

视图文件中,增加分页的显示,如下


<table>

<thead>

<tr>

<th>model</th>

<th>属性</th>

</tr>

</thead>


<tbody>

<?php foreach($values as $key => $value){?>

<tr>

<td></td>

<td></td>

<?php } ?>

</tbody>

</table>

<?php echo $pagination;?>//分页显示





原文地址:https://www.cnblogs.com/aprils/p/5123695.html