Welcome Guest, Not a member yet? Register   Sign In
how to edit custom pagination 4.3.2 like this
#1

(This post was last modified: 03-04-2023, 01:58 AM by startup.)

can you show me how to edit custom pagination 4.3.2 show like
Code:
<div align="center" id="pagination_link">
<nav aria-label="Page navigation">
    <ul class="pagination">
   
            <li class="active">
            <a href="#" class="page-link" data-ci-pagination-page="1">1</a>
        </li>
            <li><a href="#/2" class="page-link" data-ci-pagination-page="2">2</a>
        </li>
            <li>
            <a href="#/3" class="page-link" data-ci-pagination-page="3">3</a>
        </li>
            <li>
            <a href="#/4" class="page-link" data-ci-pagination-page="4">4</a>
        </li>
   
            <li>
            <a href="#2" class="page-link" aria-label="Next" data-ci-pagination-page="2">
                <span aria-hidden="true">next</span>
            </a>
        </li>
        <li>
            <a href="#10" class="page-link" aria-label="Last" data-ci-pagination-page="10">
                <span aria-hidden="true">last</span>
            </a>
        </li>
        </ul>
</nav></div>
i am doing pagination like this web demo 

i custom this but dont work next last
CONTROLLER
PHP Code:
$page=$uri->getSegment(3);
            if(empty($page) || $page == 1)
            {
                $i=0;
            }else{
                $i=$per_page*($page-1);
            }
            
            

            $output 
= array(
                'pagination_link'  => $this->pager->makeLinks($page$per_page$total_rows'ajax-page'$uri_segment),
                'product_list'  => $mfetch->fetchData($per_page$i$minimum_price$maximum_price$brand$ram$storage)
            );
            echo json_encode($output); 

PHP Code:
<?php 
use CodeIgniter\pager\PagerRender;
$pager->setSurroundCount(3?>

<nav aria-label="Page navigation">
    <ul class="pagination" >
    <?php if ($pager->hasPrevious()) : ?>
        <li>
            <a href="<?= $pager->getFirst() ?>" class="page-link" aria-label="<?= lang('Pager.first'?>">
                <span aria-hidden="true"><<</span>
            </a>
        </li>
        <li>
            <a href="<?= $pager->getPrevious() ?>" class="page-link" aria-label="<?= lang('Pager.previous'?>">
                <span aria-hidden="true"><</span>
            </a>
        </li>
    <?php endif ?>

    <?php foreach ($pager->links() as $link): ?>
        <li <?= $link['active'] ? 'class="active"' '' ?>>
            <a href="#/<?= $link['title'?>" class="page-link" data-ci-pagination-page="<?= $link['title'?>"> 
                <?= $link['title'?>
            </a>
        </li>
    <?php endforeach ?>

    <?php if ($pager->hasNext()) : ?>
        <li>
            <a href="#<?= $link['title'?>" class="page-link" aria-label="<?= lang('Pager.next'?>" data-ci-pagination-page="<?= $link['title'?>" rel="next">
                <span aria-hidden="true">></span>
            </a>
        </li>
        <li>
            <a href="#<?= $link['title'?>" class="page-link" aria-label="<?= lang('Pager.last'?>" data-ci-pagination-page="<?= $link['title'?>">
                <span aria-hidden="true">>></span>
            </a>
        </li>
    <?php endif ?>
    </ul>
</nav> 


thank you for watchinh

i dont know how to do correctly or not but work for me. so i note again someone i need

i edit custom my pagination below:
PHP Code:
<?php 
use CodeIgniter\pager\PagerRender;
$pager->setSurroundCount(2);

function 
getUrlAjax($url=''){
 
$url substr(strrchr($url"="), );
 return 
$url
}
?>

    <ul class="pagination" >
    <?php if ($pager->hasPreviousPage()) : ?>
        <li>
 <?php
 $getNumFirstPage 
$pager->getFirst(); $FirstNum=getUrlAjax($getNumFirstPage);
 if(
$FirstNum):
 
?>
            <a href="#/<?= $FirstNum ?>" data-ci-pagination-page="<?= $FirstNum?>">
                <span aria-hidden="true"> << </span>
            </a>
 <?php endif; ?>
        </li>
 
        <li>
 <?php
 $getNumPreviousPage 
$pager->getPreviousPage(); $PreviousNum=getUrlAjax($getNumPreviousPage);
 if(
$PreviousNum):
 
?>
 
            <a href="#/<?= $PreviousNum ?>" data-ci-pagination-page="<?= $PreviousNum?>">
                <span aria-hidden="true"><</span>
            </a>
 <?php endif ?>
        </li>
 
    <?php endif ?>
    <?php foreach ($pager->links() as $link):?>
        <li <?= $link['active'] ? 'class="active"' '' ?>>
            <a href="#/<?= $link['title'?>" data-ci-pagination-page="<?= $link['title'?>" > 
                <?= $link['title'?>
            </a>
        </li>
    <?php endforeach ?>
    <?php if ($pager->hasNext()):?>
        <li>
 <?php
 $getNumNextPage 
$pager->getNextPage(); $nextNum=getUrlAjax($getNumNextPage);
 if(
$nextNum):
 
?>
            <a href="#/<?= $nextNum ?>" data-ci-pagination-page="<?= $nextNum?>" >
                <span aria-hidden="true">></span>
            </a>
 <?php endif ?>
        </li>
        <li>
 <?php
 $getNumLastPage 
$pager->getLast(); $LastNum=getUrlAjax($getNumLastPage);
 if(
$LastNum):
 
?>
            <a href="#/<?= $LastNum ?>" data-ci-pagination-page="<?= $LastNum?>">
                <span aria-hidden="true">>></span>
            </a>
 <?php endif ?>
        </li>
    <?php endif ?>
    </ul> 
Reply
#2

Please Read:

CodeIgniter 4 User Guide - Library Reference - Pagination - Customizing the Links

Here is an Example for Bootstrap 5.3.0. Folders Views/Pager/bs_full nad bs_simple.
app/Views/Pager/bs_full.php
PHP Code:
<?php

/**
 * bs_full.php - - Bootstrap 5.3.0 Pager Template.
 * @var \CodeIgniter\Pager\PagerRenderer $pager
 */

$pager->setSurroundCount(2);
?>

<nav aria-label="<?= lang('Pager.pageNavigation'?>">
 <ul class="pager pagination justify-content-center">
 <?php if ($pager->hasPreviousPage()) : ?>
 <li class="page-item">
 <a class="page-link" href="<?= $pager->getFirst() ?>" aria-label="<?= lang('Pager.first'?>">
 <span aria-hidden="true"><?= lang('Pager.first'?></span>
 </a>
 </li>
 <li class="page-item">
 <a class="page-link" href="<?= $pager->getPreviousPage() ?>" aria-label="<?= lang('Pager.previous'?>">
 <span aria-hidden="true"><?= lang('Pager.previous'?></span>
 </a>
 </li>
 <?php endif ?>

 <?php foreach ($pager->links() as $link) : ?>
 <li <?= $link['active']  'class="page-item active"' '' ?>>
 <a class="page-link" href="<?= $link['uri'?>">
 <?= $link['title'?>
 </a>
 </li>
 <?php endforeach ?>

 <?php if ($pager->hasNextPage()) : ?>
 <li class="page-item">
 <a class="page-link" href="<?= $pager->getNextPage() ?>" aria-label="<?= lang('Pager.next'?>">
 <span aria-hidden="true"><?= lang('Pager.next'?></span>
 </a>
 </li>
 <li class="page-item">
 <a class="page-link" href="<?= $pager->getLast() ?>" aria-label="<?= lang('Pager.last'?>">
 <span aria-hidden="true"><?= lang('Pager.last'?></span>
 </a>
 </li>
 <?php endif ?>
 </ul>
</nav> 
app/Views/Pager/bs_simple.php
PHP Code:
<?php
/**
 * bs_simple - Bootstrap 5.3.0 Pager Template.
 * @var \CodeIgniter\Pager\PagerRenderer $pager
 */

$pager->setSurroundCount(0);
?>
<nav aria-label="Page Results">
 <ul class="pager pagination justify-content-center">
 <li <?= $pager->hasPrevious() ? 'class="page-item active"' 'class="page-item disabled"' ?>>
 <a class="page-link" href="<?= $pager->getPrevious() ?? '#' ?>" aria-label="<?= lang('Pager.previous'?>">
 <span aria-hidden="true"><?= lang('Pager.newer'?></span>
 </a>
 </li>
 <li <?= $pager->hasNext() ? 'class="page-item active"' 'class="page-item disabled"' ?>>
 <a class="page-link" href="<?= $pager->getnext() ?? '#' ?>" aria-label="<?= lang('Pager.next'?>">
 <span aria-hidden="true"><?= lang('Pager.older'?></span>
 </a>
 </li>
 </ul>
</nav> 
app/Config/Pager/Pager.php
PHP Code:
<?php

namespace Config;

use 
CodeIgniter\Config\BaseConfig;

class 
Pager extends BaseConfig
{
 
/**
 * --------------------------------------------------------------------------
 * Templates
 * --------------------------------------------------------------------------
 *
 * Pagination links are rendered out using views to configure their
 * appearance. This array contains aliases and the view names to
 * use when rendering the links.
 *
 * Within each view, the Pager object will be available as $pager,
 * and the desired group as $pagerGroup;
 *
 * @var array<string, string>
 */
 
public $templates = [
 
'default_full'  => 'CodeIgniter\Pager\Views\default_full',
 
'default_simple' => 'CodeIgniter\Pager\Views\default_simple',
 
'default_head'  => 'CodeIgniter\Pager\Views\default_head',
        // Bootstrap 5.3.0 Pager Templates.
 
'bs_full'        => 'Pager\bs_full',
 
'bs_simple'      => 'Pager\bs_simple',
 ];

 
/**
 * --------------------------------------------------------------------------
 * Items Per Page
 * --------------------------------------------------------------------------
 *
 * The default number of results shown in a single page.
 *
 * @var integer
 */
 
public $perPage 20;

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(03-04-2023, 12:32 AM)InsiteFX Wrote: Please Read:

CodeIgniter 4 User Guide - Library Reference - Pagination - Customizing the Links

Here is an Example for Bootstrap 5.3.0. Folders Views/Pager/bs_full nad bs_simple.
app/Views/Pager/bs_full.php
PHP Code:
<?php

/**
 * bs_full.php - - Bootstrap 5.3.0 Pager Template.
 * @var \CodeIgniter\Pager\PagerRenderer $pager
 */

$pager->setSurroundCount(2);
?>

<nav aria-label="<?= lang('Pager.pageNavigation'?>">
 <ul class="pager pagination justify-content-center">
 <?php if ($pager->hasPreviousPage()) : ?>
 <li class="page-item">
 <a class="page-link" href="<?= $pager->getFirst() ?>" aria-label="<?= lang('Pager.first'?>">
 <span aria-hidden="true"><?= lang('Pager.first'?></span>
 </a>
 </li>
 <li class="page-item">
 <a class="page-link" href="<?= $pager->getPreviousPage() ?>" aria-label="<?= lang('Pager.previous'?>">
 <span aria-hidden="true"><?= lang('Pager.previous'?></span>
 </a>
 </li>
 <?php endif ?>

 <?php foreach ($pager->links() as $link) : ?>
 <li <?= $link['active']  'class="page-item active"' '' ?>>
 <a class="page-link" href="<?= $link['uri'?>">
 <?= $link['title'?>
 </a>
 </li>
 <?php endforeach ?>

 <?php if ($pager->hasNextPage()) : ?>
 <li class="page-item">
 <a class="page-link" href="<?= $pager->getNextPage() ?>" aria-label="<?= lang('Pager.next'?>">
 <span aria-hidden="true"><?= lang('Pager.next'?></span>
 </a>
 </li>
 <li class="page-item">
 <a class="page-link" href="<?= $pager->getLast() ?>" aria-label="<?= lang('Pager.last'?>">
 <span aria-hidden="true"><?= lang('Pager.last'?></span>
 </a>
 </li>
 <?php endif ?>
 </ul>
</nav> 
app/Views/Pager/bs_simple.php
PHP Code:
<?php
/**
 * bs_simple - Bootstrap 5.3.0 Pager Template.
 * @var \CodeIgniter\Pager\PagerRenderer $pager
 */

$pager->setSurroundCount(0);
?>
<nav aria-label="Page Results">
 <ul class="pager pagination justify-content-center">
 <li <?= $pager->hasPrevious() ? 'class="page-item active"' 'class="page-item disabled"' ?>>
 <a class="page-link" href="<?= $pager->getPrevious() ?? '#' ?>" aria-label="<?= lang('Pager.previous'?>">
 <span aria-hidden="true"><?= lang('Pager.newer'?></span>
 </a>
 </li>
 <li <?= $pager->hasNext() ? 'class="page-item active"' 'class="page-item disabled"' ?>>
 <a class="page-link" href="<?= $pager->getnext() ?? '#' ?>" aria-label="<?= lang('Pager.next'?>">
 <span aria-hidden="true"><?= lang('Pager.older'?></span>
 </a>
 </li>
 </ul>
</nav> 
app/Config/Pager/Pager.php
PHP Code:
<?php

namespace Config;

use 
CodeIgniter\Config\BaseConfig;

class 
Pager extends BaseConfig
{
 
/**
 * --------------------------------------------------------------------------
 * Templates
 * --------------------------------------------------------------------------
 *
 * Pagination links are rendered out using views to configure their
 * appearance. This array contains aliases and the view names to
 * use when rendering the links.
 *
 * Within each view, the Pager object will be available as $pager,
 * and the desired group as $pagerGroup;
 *
 * @var array<string, string>
 */
 
public $templates = [
 
'default_full'  => 'CodeIgniter\Pager\Views\default_full',
 
'default_simple' => 'CodeIgniter\Pager\Views\default_simple',
 
'default_head'  => 'CodeIgniter\Pager\Views\default_head',
        // Bootstrap 5.3.0 Pager Templates.
 
'bs_full'        => 'Pager\bs_full',
 
'bs_simple'      => 'Pager\bs_simple',
 ];

 
/**
 * --------------------------------------------------------------------------
 * Items Per Page
 * --------------------------------------------------------------------------
 *
 * The default number of results shown in a single page.
 *
 * @var integer
 */
 
public $perPage 20;


I have also asked a question similar to this. Here is the link.
https://forum.codeigniter.com/showthread.php?tid=87169

But how to ovverride $pager->getFirst() and $pager->getPreviousPage() method to check if page is first page i.e. no 1, and if condition is matched, do not add the page number to url. For example,
http://example.com/post/page/1 convert to http://example.com/post.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB