Welcome Guest, Not a member yet? Register   Sign In
How to create pagination on CI4
#12

(This post was last modified: 04-11-2020, 12:52 AM by wdeda.)

Thank you! Amazing how a simple detail changes everything. As soon as I saw your post the solution to my problem came complete at once.
In addition to the model that collects the table data, I created another one where the table fields are selected according to the search argument.

PHP Code:
<?php namespace App\Controllers;
 
 
//20200410
 
    use CodeIgniter\Controller;
    use App\Models\AlbunsListModel;
 use 
App\Models\AlbunsGenresModel;

    class Albumlists extends Controller {    
        
    
public function genre1()
    {        
        $listModel 
= new AlbunsListModel();
        $genresModel = new AlbunsGenresModel();

        $style $genresModel->getGenre1();
                
        $data 
= [
            'genre1' => $listModel->orderBy('player_id''ano''title''asc')
            ->where('style1'$style)
            ->paginate(20),
            'pager' => $listModel->pager,
            'total' => $genresModel->numGenre1(),
            'genre' => $genresModel->getGenre1()
        ];
        
        $genre 
$genresModel->getGenre1();

        $header = array ( 
 
'icon' => 'favicon'
 
'css' => 'albumlists',
 
'title' => $genre'records. - wdeda',
 
'action' => '/ci4/search/allmedia/',
 
'placeholder' => 'Pesquisar'
 
);

 echo 
view('templates/header'$header);
 echo 
view('content/albums/genre1'$data); 
 echo 
view('templates/footer');
    }
//and so on... 

 There is still a pending detail. In the page header I inform the number of items listed in relation to the total pages:
1->20 of 1426 titles, for example, but I need the segment number instead of the query parameter:

http://localhost/ci4/albumlists/genre1/2384/20 instead http://localhost/ci4/albumlists/genre1/2384?page=2

PHP Code:
<? php
if ($this->uri->segment (4)! = null)
{
$ seg = $this->uri->segment (4);
}else{
$seg = 0;
}
$pg = $seg + 20;
$prv = 1 + $seg;
if ($pg == null)
{
$pg = 20;
$prv = 1;
echo "$prv-$pg of $total title(s).";
}elseif ($pg > $ total)
{
echo "$prv-$total of $total title (s).";
}else{
echo "$prv-$ pg of $total title (s)."; 

The manual has an example how I can use the segment number instead of the query parameter that would resolve the pending issue, but I'm an old man, everything is slow, I still can't understand where the change is made and how.

<?= $ pager->makeLinks($ page, $ perPage, $ total, 'template_name', $ segment)?>

"When you look at an abyss for a long time, the abyss looks at you."
(Nietzsche)

From time to time I will look at this but only a little.
Once again, thank you very much!
Reply


Messages In This Thread
How to create pagination on CI4 - by Marcolino92 - 04-08-2020, 10:15 AM
RE: How to create pagination on CI4 - by wdeda - 04-09-2020, 08:38 AM
RE: How to create pagination on CI4 - by wdeda - 04-09-2020, 10:44 AM
RE: How to create pagination on CI4 - by wdeda - 04-09-2020, 01:01 PM
RE: How to create pagination on CI4 - by waleed - 02-18-2021, 03:08 AM
RE: How to create pagination on CI4 - by Mano - 09-17-2021, 05:29 PM
RE: How to create pagination on CI4 - by wdeda - 04-10-2020, 05:09 PM
RE: How to create pagination on CI4 - by InsiteFX - 09-18-2021, 01:07 AM
RE: How to create pagination on CI4 - by danger89 - 02-26-2024, 05:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB