• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create pagination on CI4

#11
EDIT:

'test' => $model->orderBy('id', 'DESC')->paginate(2, 'res'),
Reply

#12
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 $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

#13
(04-09-2020, 11:00 PM)jouharjaseemak Wrote: finaly i have find a solution...any one want it ?
Yes, Plz share
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.