benedmunds / CodeIgniter-Ion-Auth

Simple and Lightweight Auth System for CodeIgniter
http://benedmunds.com/ion_auth/
MIT License
2.34k stars 1.14k forks source link

help pagination not works when i try to impelement using pagination library #347

Closed hengkiardo closed 11 years ago

hengkiardo commented 11 years ago

$this->load->library('pagination');

    $config['base_url'] = $this->config->item('base_url').'admin/user/index';
    $config['total_rows'] = count($this->ion_auth->users()->result());
    $config['per_page'] = 1;
    $config['uri_segment'] = 4;
    $config['num_links'] = 3;

    $config['full_tag_open'] = '<ul>';
    $config['full_tag_close'] = '</ul>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $config['first_link'] = 'First';
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['last_link'] = 'Last';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';
    $config['next_link'] = 'Next';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['prev_link'] = 'Prev';
    $config['prev_tag_open'] = '<li>';
    $config['prev_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="active"><a>';
    $config['cur_tag_close'] = '</a></li>';

    $this->pagination->initialize($config);

    $this->data['users'] = $this->ion_auth->users()->result(false, $config['per_page'], $this->uri->segment(4) );

    foreach ($this->data['users'] as $k => $user){
        $this->data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result();
    }

    $this->data['pagination'] = $this->pagination->create_links();
benedmunds commented 11 years ago

You need to do it like this:

$this->data['users'] = $this->ion_auth->users()->limit($config['per_page'])->offset($this->uri->segment(4))->result();
hengkiardo commented 11 years ago

Hai Ben,

i try to use like you tell, but still not working.

the results still give all records from the table user.

benedmunds commented 11 years ago

What happens if you manually set the limits, something like this:

$this->data['users'] = $this->ion_auth->users()->limit(2)->offset(1)->result();

hengkiardo commented 11 years ago

still same :(

hengkiardo commented 11 years ago

hi ben,

how to fix that?

benedmunds commented 11 years ago

How many users do you have?

jacobkball commented 11 years ago

I used something like:

    $config['base_url'] = base_url().'/admin/user';
    $config['total_rows'] = $this->ion_auth->users()->num_rows();
    $config['per_page'] = '30';
    $the_uri_segment = 3;
    $config['uri_segment'] = $the_uri_segment;

    $this->data['users'] = $this->ion_auth->offset($this->uri->segment($the_uri_segment))->limit($config['per_page'])->users()->result();
    foreach ($this->data['users'] as $k => $user)
    {
        $this->data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result();
    }

and I've been able to paginate my users.

hengkiardo commented 11 years ago

@jacobkball thanks so bro, now its works

benedmunds commented 11 years ago

Thanks @jacobkball!

sagun24 commented 11 years ago

how did you generate the pagination links???

vosydao commented 9 years ago

i have code controller :

         public function index()
{
    $this->load->helper('file');
    $this->load->helper('form');
    $this->load->helper('url');

    if (!$this->ion_auth->logged_in())
    {
        redirect('dashboard/login', 'refresh');
    }
    elseif (!$this->ion_auth->is_admin())
    {
        return show_error('You must be an administrator to view this page.');
    }
    else
    {
         $config = array();
        $this->load->library('pagination');
        $config['base_url'] = base_url('manager_user');
        $config['total_rows'] = $this->ion_auth->users()->num_rows();
        $config['per_page'] = '2';
        $config['num_links'] = 10;
        $the_uri_segment = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $config['uri_segment'] = $the_uri_segment;
        $this->pagination->initialize($config);

        $data['users'] =   $this->ion_auth->offset($this->uri->segment($the_uri_segment))->limit($config['per_page'])->users()->result();

        foreach ($data['users'] as $k => $user)
        {
            $data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result();
        }
        $data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

        $data['links'] = $this->pagination->create_links();
        $name =$username = $this->session->userdata( 'username' );
        $data['subview'] = 'views/manager_user/index';
        $data['title'] = 'Manager user';
        $data['username']=$name;
        $this->load->view('template/layout',$data);

but, moving to the next page, the error Warning: include(D:\xamp\htdocs\CI_demo\application\errors\html\error_php.php): failed to open stream: No such file or directory in D:\xamp\htdocs\CI_demo\system\core\Exceptions.php on line 269 thanks

aplusphilic commented 9 years ago

How is this related to Ion Auth library? Please use discussion forums for this. On Dec 5, 2014 12:33 PM, "vosydao" notifications@github.com wrote:

i have code controller :

     public function index()

{ $this->load->helper('file'); $this->load->helper('form'); $this->load->helper('url');

if (!$this->ion_auth->logged_in())
{
    redirect('dashboard/login', 'refresh');
}
elseif (!$this->ion_auth->is_admin())
{
    return show_error('You must be an administrator to view this page.');
}
else
{
     $config = array();
    $this->load->library('pagination');
    $config['base_url'] = base_url('manager_user');
    $config['total_rows'] = $this->ion_auth->users()->num_rows();
    $config['per_page'] = '2';
    $config['num_links'] = 10;
    $the_uri_segment = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $config['uri_segment'] = $the_uri_segment;
    $this->pagination->initialize($config);

    $data['users'] =   $this->ion_auth->offset($this->uri->segment($the_uri_segment))->limit($config['per_page'])->users()->result();

    foreach ($data['users'] as $k => $user)
    {
        $data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result();
    }
    $data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

    $data['links'] = $this->pagination->create_links();
    $name =$username = $this->session->userdata( 'username' );
    $data['subview'] = 'views/manager_user/index';
    $data['title'] = 'Manager user';
    $data['username']=$name;
    $this->load->view('template/layout',$data);

but, moving to the next page, the error Warning: include(D:\xamp\htdocs\CI_demo\application\errors\html\error_php.php): failed to open stream: No such file or directory in D:\xamp\htdocs\CI_demo\system\core\Exceptions.php on line 269 thanks

— Reply to this email directly or view it on GitHub https://github.com/benedmunds/CodeIgniter-Ion-Auth/issues/347#issuecomment-65766158 .

RizalG commented 9 years ago

I want to ask, how do you restrict access to the admin user pages member. For example, I logged in admin page ... but I try to access the page the user can direct members to access without a password, i wants when I click page of my members do not have access to it

benedmunds commented 9 years ago

Just check their group and handle the logic appropriately.

adipatiarya commented 7 years ago

yess this work for me.