Pagination Library



( ZN >= 1.0.0 )

It was created to do paging operations. There are 2 ways to monitor for paging . The first is the use of the Pagination class directly . The other is DB :: pagination () method of the library . The second method actually uses the Pagination class, and the practicality is that the paging bar is shaped directly according to the database query. The following examples are provided for the use of both. We recommend using the second method, as it is usually paged according to the data coming from the database.

 

 

# Section Headings


# Configuration
# Schema
# DB :: pagination ()
# Ajax Paging

 

 

# Configuration


The paging settings are in the following file. These are the default settings. If desired, the settings can be intervened by methods.

File: Config / ViewObjects.php
String $ Prev Game Determine how to display the previous page link.
String $ NextName Determine how to display the next page link.
String $ Firstname How the first page link is displayed is determined.
String $ LastName How to display the last page link is determined.
Int $ totalrows The total number of records is set.
Int $ start The record start index is specified.
Int $ limit The escape is determined by the page.
Int $ countlinks The maximum number of links to be created by the paging bar is determined.
String $ type = 'classic' Which type of pagination can be used with.
ajax This option allows the counting links to get some property and value pairs so that you can use paging with ajax.
classic It creates a classic paging bar.
String $ output = 'bootstrap' It enables the paging bar to be compatible with bootstrap.
bootstrap The paging bar is affected by the bootrap's style and css structure.
classic It produces a padding bar that you can design for yourself.
Array $ style = [] current The active page is for giving the link style. Used to give style to paging bar.
links It is meant to give style to all the links in the paging bar.
prev The previous page is for linking style.
NeXT The next page is for linking style.
first The first page is for giving the link style.
last The last page is for giving the link style.
Array $ class = [] current The active page is for linking css class. It is for applying css classes to the paging bar.
links All links in the paging bar are for css class.
prev The previous page is for linking css class.
NeXT The next page is for linking css class.
first The first page is for linking css class.
last The last page is for linking css class.

 

 

# Methods


String create ( Int $ start , Array $ settings = [] )
this url ( String $ url )
this start ( Int $ start )
this limit ( Int $ limit )
this totalRows ( Int $ totalRows )
this countLinks ( Int $ countLinks )
this linkNames ( String $ prev , String $ next , String $ first , String $ last )
this style ( Array $ style )
this css ( Array $ css )
this settings ( Array $ config = [] )
this type ( String $ type )
this output ( String $ type )
String DB :: pagination ( String $ url = NULL , Array $ settings = NULL )

 

 

# Create ( ZN> = 0.0.1 )


Used to create a paging bar.

Parameters

scaler $ start  =  NULL Record start index. Usage is not required unless required.
Array $ settings  =  NULL Paging settings. Usage is not required unless it is necessary. The settings () method can also be used for this parameter .
return String

Use of

echo Pagination::create();
echo Pagination::create(URI::segment(-1),
[
     'style' => ['links' => 'color:red']
]);

In the second example, we use URI :: segment (-1) for parameter 1, because the purpose of the paging record number is in the last part of the URL. If the paging record number is in a different partition, you can assign that segment's 1st segment to the 1st parameter.

 

 

# URL ( ZN> = 0.0.1 )


The paging library runs through the URL as long as type: classic is set in the paging settings . For this reason, it should be specified which URL the paging bar will work with. Normally you do not need to use this method. Because the paging library automatically pre- sets the existing link . However, you can use this method if you need to specify exceptions and URLs in exceptional cases.

Parameters

String $ url It is determined which url the paging bar will handle.
return this

Use of

echo Pagination::url('products/comments')->create();
< A href = "https://www.xxx.xxx/products/comments/0"> 1 < / a >
< a href = "https://www.xxx.xxx/products/comments/10"> 2 < / a >
< a href = "https://www.xxx.xxx/products/comments/20"> 3 < / a >
< a href = "https://www.xxx.xxx/products/comments/ 30 "> 4 < / a >
< a href =" https://www.xxx.xxx/products/comments/40 "> 5 < / a >
< a href =" https://www.xxx.xxx/ products / comments / 10 ">> < / a >

 

 

# Start ( ZN >= 0.0.1 )


The page process is set to start from which record . It is equivalent to parameter 1 of the create () method . Since the registration number will change as the page is passed, this method is assigned to the registration index in the URL as the parameter . However, the paging library does not require this operation by default. It is automatically based on the record index number of the last partition in the URL. URLit is necessary to use this method when it is necessary to use it outside the normal structure, that is, when the last section of the URL does not have a registration index.

Parameters

String * | * Int $ start = NULL Record start index.
Return * this

Use of

echo Pagination::start(URI::get('row'))
               ->url('products/comments')
               ->create();

 

 

# Limit ( ZN >= 0.0.1 )


It is used to set how many pages each record will hold.

Parameters

Int $ limit It sets how many paging paging will be.
return this

Use of

echo Pagination::start(URI::get('row'))
               ->url('products/comments')
               ->limit(5)
               ->create();

 

 

# TotalRows ( ZN >= 0.0.1 )


It is specified how many records will be subject to paging.

Parameters

Int $ totalrows Total number of records.
return this

Use of

echo Pagination::start(URI::get('row'))
               ->url('products/comments')
               ->limit(15)
               ->totalRows(200)
               ->create();

 

 

# CountLinks ( ZN >= 0.0.1 )


The total in the paging bar kaç linkinwill be displayed.

Parameters

Int $ countlinks Total number of links. Only numbered links are processed.
return this

Examples

echo Pagination::start(URI::get('row'))
               ->url('products/comments')
               ->limit(15)
               ->totalRows(200)
               ->countLinks(3)
               ->create();

 

 

# LinkNames ( ZN >= 0.0.1 )


Önceki, sonraki, ilkAnd sonthe page links, which will be used to set the name or shape displayed.

Parameters

String $ Prev Game The name of the previous page link.
String $ NextName The name of the next page link.
String $ Firstname First page link name.
String $ LastName Last page link name.
return this

Use of

echo Pagination::start(URI::get('row'))
               ->url('products/comments')
               ->limit(15)
               ->totalRows(200)
               ->countLinks(3)
               ->linkNames('[ prev ]', '[ next ]', '[+ first +]', '[+ last +]')
               ->create();

 

 

# Style ( ZN >= 0.0.1 )


It is used to apply styles to links in the paging bar.

Parameters

Array $ Style Defines the styles that will be applied to the pagination links.
Available Keys
current The active page is for giving the link style.
links It is meant to give style to all the links in the paging bar.
prev The previous page is for linking style.
NeXT The next page is for linking style.
first The first page is for giving the link style.
last The last page is for giving the link style.
return this

Use of

echo Pagination::start(URI::get('row'))
               ->url('products/comments')
               ->limit(15)
               ->totalRows(200)
               ->countLinks(3)
               ->linkNames('[ prev ]', '[ next ]', '[+ first +]', '[+ last +]')
               ->style(['links' => 'color:green;', 'current' => 'font-size:30px;'])
               ->create();

 

 

# CSS ( ZN >= 0.0.1 )


The above styleuses the same logic as the individual. Only css classes are applied instead of style.

Parameters

Array $ Style Defines the css classes that will be applied to the pagination links.
return this

 

 

# Output ( ZN FE 5.5.70 - ZN 5.5.10 )


The output of the paging bar is used to change the track. In classic use, the paging bar consists only of [a] tags and includes the use of [ul] and [li] in the use of bootstrap.

Parameters

String $ Type If this parameter  is set to bootstrap , the output view becomes the bootstrap paging bar.
return this

Use of

echo Pagination::start(URI::get('row'))
               ->output('bootstrap')
               ->url('products/comments')
               ->limit(15)
               ->totalRows(75)
               ->countLinks(5)
               ->create();

 

 

# DB :: pagination () ( ZN >= 2.0.5 )


It is used to create a direct page bar after database queries.

Parameters

String $ url = NULL Performs the same task as the url () method.
Array $ settings = NULL It assumes the same task as the settings () method.
return String

Use of

$get = DB::limit(NULL, 1)->get('users');

output( $get->result() );

echo $get->pagination(NULL,
[
    'style' =>
    [
        'current' => 'color:red'
    ]
]);
0 => object
(
        name     => string 'example' (length = 7 ) ,
        id       => string '30' (length = 4 ) ,
        user_id => string '131' (length = 5 )
)

< 1 2 3 4 5 >

 

 

# Ajax Paging


For Ajax paging, the type key in the configuration file must first be configured as ajax .

'type' => 'ajax'

This page contains some values ​​that you can use with ajax if you review the links in paging.

< A href = "# = 4 prowler" prowler = "4" pType = "ajax" > 1 < / a >

The prow attribute in the above statement holds the registration number, while the ptype value is a selector that separates this tag from the others. These values ​​will be used during the ajax submission.

Create Controller

Create a controller for paging and view calling.

File: Controllers / Home.php
<?php namespace Project\Controllers;

use Import, Http;

class Home extends Controller
{
    public function main(String $params = NULL)
    {   
        
    }

    public function ajaxPagination()
    {
        if( ! Http::isAjax() )
        {
            return false;    
        }

        Import::view('Home/pagination');
    }
}

Create Views

Home:main create the view file that your controller will automatically load.

File: Views / Home / main.wizard.php
{[ Import::style('bootstrap'); Import::script('jquery'); ]} 

<div id="content"> 
    @Import::view('HomePagination') 
</div>

The content that will change when clicking the link in the paging bar needs to be kept in a separate view file.

File: Views / Home / pagination.wizard.php
{[ $menus = DB::limit(Post::row() ?: NULL, 2)->menus(); ]}

<table class="table table-striped">
    <thead>
        <tr><td>ID</td><td>NAME</td><td>URL</td></tr>
    </thead>
    <tbody>
        @foreach( $menus->result() as $row )
        <tr><td>$row->id</td>$row->name</td><td>$row->url</td></tr>
        @endforeach
        <tr><td colspan="3">$menus->pagination()</td></tr>
    </tbody>
</table>

<script>
    $('#content a[ptype="ajax"]').click(function()
    {
        $.ajax
        ({
            url: 'Home/ajaxPagination',
            data: {'row': $(this).attr('prow')},
            type: 'post',
            success: function(data)
            {
                $('#content').html(data);
            }
        });
    })
</script>