Gleez sub-page function optimization

Source: Internet
Author: User
Tags php foreach

Gleez sub-page function optimization

When a method in a controller only calls the paging function, and in the index method, there is no need for the following optimization, otherwise it can be optimized according to the proposed content;


Locate the URL method under the/modules/gleez/classes/gleez/pagination.php file, and modify the contents to see the red font


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) ));

When paging is invoked, the query page is incremented directly in the URL link, otherwise the URL displayed defaults to the method of the controller's index, and the query pages are incremented (and the URL omits the index method name display)

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 ' # ';

}


The method of invoking paging function in the Controller method is as follows:

Public Function Action_select ()

{

$this->title = __ (' paged test ');

$sql _p = "SELECT * FROM Products";

$p _values = Db::query (Database::select, $sql _p)

->execute ()

->as_array ();

Calculate the total query record

$count = count ($p _values);

Page out

$pagination = pagination::factory (Array (

' items_per_page ' =>20,

' total_items ' = $count,

' uri '= = $this->request->uri (),//optimize paging function, new

));


$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 ();

Load attempts to

$view = view::factory (' Fenye ')

->bind ("pagination", $pagination)

->bind ("P_values", $values);

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

}

View file, increase the display of pagination, as follows


<table>

<thead>

<tr>

<th>model</th>

<th> Properties </th>

</tr>

</thead>


<tbody>

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

<tr>

<td></td>

<td></td>

<?php}?>

</tbody>

</table>

<?php echo $pagination;? >//pagination Display





Gleez sub-page function optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.