Welcome Guest, Not a member yet? Register   Sign In
Pagination
#1

(This post was last modified: 03-25-2022, 07:42 PM by Z4K7.)

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,

        ]);

    
Reply
#2

At first glance I would have thought it would be 'pager' instead of 'page' but I haven't looked into it closely.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#3

(This post was last modified: 03-25-2022, 10:04 PM by luckmoshy.)

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,

        ]);

    } 
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#4

(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
Reply
#5

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

Your doing it all wrong.
What did you Try? What did you Get? What did you Expect?

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

(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.
Reply
#7

In my blog I get category blogs and it returns correct, I look at my code and see how I did it.
What did you Try? What did you Get? What did you Expect?

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

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.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#9

(This post was last modified: 03-28-2022, 08:19 AM by Z4K7.)

(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
Reply
#10

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

https://codeigniter.com/user_guide/libra...ation.html
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply




Theme © iAndrew 2016 - Forum software by © MyBB