CodeIgniter Forums
Pagination - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Pagination (/showthread.php?tid=81603)

Pages: 1 2


Pagination - Z4K7 - 03-25-2022

Hello I hope you can help me I try to make a pagination with CI4 but I have not succeeded



At the time of consulting the DB, only specific profiles are requested, which is number 3



Model



PHP Code:
public function getAll$start 0$limit 0,$role_id '3')
 {
 return 
$this->users_query($start$limit,$role_id)->getResultArray();
 }

 public function 
users_query($start 0$limit 0$role_id '3')
 {
 
$builder $this->db->table('usuarios');
 
$builder->select('usuarios. id,usuario,email,Admission_date,update_date,unique_id,last_login, grupos_perfiles.id_perfil,perfiles.name');
 
$builder->limit(100);
 
$builder->orderBy('id''asc');
 
$builder->join(
 
'grupos_perfiles',
 
'grupos_perfiles.user_id=usuarios.id',
 );
 
$builder->join(
 
'perfiles',
 
'perfiles.id=grupos_perfiles.id_perfil',
 );
 
$builder->where('grupos_perfiles.id_perfil'$role_id);
        

        
if (!empty($limit) || !empty($start)) {
 
$builder->limit($limit$start);
 }
 return 
$builder->get();
 } 


Controller



When I do pager to get it out it doesn't work it throws me an error.


ErrorException

Trying to get property 'page' of non-object

PHP Code:
public function index()
    {
 
$pager = \Config\Services::pager();
 
$model = new \App\Models\pagination();
      $cliente $model->getAll(0,5);
 return 
view('admin/clientes/cliente',[
            'admi' => $cliente,
 
'page' => $cliente->pager,

        ]);

    



RE: Pagination - ignitedcms - 03-25-2022

At first glance I would have thought it would be 'pager' instead of 'page' but I haven't looked into it closely.


RE: Pagination - luckmoshy - 03-25-2022

PHP Code:
public function index()
    {
 
$pager = \Config\Services::pager();
 
$model = new \App\Models\pagination();
      
$cliente =  $model->paginate(5);
      
/*$cliente =$model->pager,*/
      
 
return view('admin/clientes/cliente',[ 'pager'=>$cliente->pager,

        ]);

    } 



RE: Pagination - Z4K7 - 03-26-2022

(03-25-2022, 09:58 PM)luckmoshy Wrote:
PHP Code:
public function index()
    {
 
$pager = \Config\Services::pager();
 
$model = new \App\Models\pagination();
      $cliente =  $model->paginate(5);
      /*$cliente =$model->pager,*/
 
  
 
return view('admin/clientes/cliente',[ 'pager'=>$cliente->pager,

        ]);

    
                  
It doesn't work, it lists all the users and I only need to list those with role #3  Cry


RE: Pagination - InsiteFX - 03-27-2022

I suggest that you read the CodeIgniter User Guide on Library - Pagination.

Your doing it all wrong.


RE: Pagination - Z4K7 - 03-27-2022

(03-27-2022, 12:30 AM)InsiteFX Wrote: I suggest that you read the CodeIgniter User Guide on Library - Pagination.

Your doing it all wrong.

But in this case, it only loads the complete table with all the users, but not the users that I have in a certain group. If I make a pagination to the model, it loads me without the function that I created.


RE: Pagination - InsiteFX - 03-28-2022

In my blog I get category blogs and it returns correct, I look at my code and see how I did it.


RE: Pagination - ignitedcms - 03-28-2022

Just to add to this, I would also recommend separating the flow control and focusing on just the database query, to see if it returns what you expect, before passing it through the pagination.


RE: Pagination - Z4K7 - 03-28-2022

(03-28-2022, 12:23 AM)InsiteFX Wrote: In my blog I get category blogs and it returns correct, I look at my code and see how I did it.


link blogs

(03-28-2022, 06:21 AM)ignitedcms Wrote: Just to add to this, I would also recommend separating the flow control and focusing on just the database query, to see if it returns what you expect, before passing it through the pagination.
On the part of the DB query it works without any problem, it is only the paginate section


RE: Pagination - ignitedcms - 03-28-2022

In that case, try and work backwards with a simplified example by following the documentation.

https://codeigniter.com/user_guide/libraries/pagination.html