codeigniter - How to get CI pagination to work with a array(); -


how can codeigniter pagination work $data['controller_files'][] = array()

i cannot figure out best place put uri->segment(4) , per page limit.

the pagination links work not per page. still shows full list of files on table.

routes

// extensions $route['admin/extension/permissions'] = "admin/extension/extension_permissions/index"; $route['admin/extension/permissions/(:any)'] = "admin/extension/extension_permissions/index/$1"; 

controller

<?php  class extension_permissions extends admin_controller {     public function index($offset = 0) {     $data['title'] = "permissions";      $controller_files = $this->model_extension_permissions->get_installed_permissions('name');       $data['controller_files'] = array();      $files = glob(fcpath . 'application/modules/admin/controllers/*/*.php') ;      if ($files) {          foreach ($files $file) {              $controller =  basename(strtolower($file), '.php');              $this->load->library('pagination');              $limit = 1;             $total_rows = 13; // number of current files.              $config['base_url'] = base_url()."admin/extension/permissions";             $config['total_rows'] = $total_rows;             $config['per_page'] = $limit;             $config['num_links'] = 5;             $config['uri_segment'] = 4;             $config['use_page_numbers'] = true;             $config['full_tag_open'] = '<ul class="pagination pagination-sm">';              $config['full_tag_close'] = '</ul>';              $config['num_tag_open'] = '<li>';              $config['num_tag_close'] = '</li>';              $config['cur_tag_open'] = '<li class="active"><span>';              $config['cur_tag_close'] = '<span class="sr-only">(current)</span></span></li>';              $config['prev_tag_open'] = '<li>';              $config['prev_tag_close'] = '</li>';              $config['next_tag_open'] = '<li>';              $config['next_tag_close'] = '</li>';              $config['first_link'] = '&laquo;';              $config['prev_link'] = '&lsaquo;';              $config['last_link'] = '&raquo;';              $config['next_link'] = '&rsaquo;';              $config['first_tag_open'] = '<li>';              $config['first_tag_close'] = '</li>';              $config['last_tag_open'] = '<li>';              $config['last_tag_close'] = '</li>';              $this->pagination->initialize($config);                   $modules = $this->model_extension_permissions->get_permissions_by_controller($controller);              $module_data = array();              foreach ($modules $module) {                 $module_data[] = array(                     'permission_id' => $module['permission_id'],                     'name' => ucwords(str_replace('_', ' ', $controller) . ' &gt; ' . $module['name']),                     'edit' => site_url('admin/extension/permissions/update' .'/'. $controller .'/'. $module['permission_id']),                     'delete' => site_url('admin/extension/permissions/uninstall' .'/'. $controller .'/'. $module['permission_id'])                 );             }              $data['controller_files'][] = array(                 'name' => $controller,                 'controller' => $controller,                 'module'    => $module_data,                 'install' => site_url('admin/extension/permissions/install') .'/'.$controller,                 'installed' => in_array($controller, $controller_files)             );         }     }      $this->parser->parse('template/extension/extension_permissions', $data); } } 

view

<div class="panel panel-default"> <div class="panel-heading"><h1 class="panel-title"></h1>{title}</div> <div class="panel-body"> <div class="table-responsive">  <table class="table table-striped table-bordered table-hover" > <thead>     <tr>     <td data-field="name">controller name</td>     <td class="text-right">action</td>     </tr> </thead id="mytable"> <tbody> <?php if ($controller_files) { ?> <?php foreach ($controller_files $controllers) { ?>  <tr> <td><?php echo $controllers['name']; ?></td> <td class="text-right"> <?php if (!$controllers['installed']) { ?> <a href="<?php echo $controllers['install']; ?>" class="btn btn-success"><i class="fa fa-plus-circle"></i> install</a> <?php } else { ?> <a href="<?php echo $controllers['uninstall']; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i> uninstall</a> <?php } ?> </td> </tr>  <?php foreach ($controllers['module'] $module) { ?> <tr> <td class="text-left"><?php echo $module['name']; ?></td> <td class="text-right"> <a href="<?php echo $module['delete']; ?>"  class="btn btn-danger"><i class="fa fa-trash-o"></i> uninstall</a>  <a href="<?php echo $module['edit']; ?>"  class="btn btn-primary"><i class="fa fa-pencil"></i> edit</a> </td> </tr> <?php } ?>  <?php } ?> <?php } else { ?> <tr>     <td class="text-center">no results</td> </tr> <?php } ?> </tbody> </table> </div><!-- table responsive end --> </div><!-- panel body end --> <div class="panel-footer">     <div class="clearfix">         <div class="pull-left">             <?php echo $this->pagination->create_links();?>         </div>         <div class="pull-right">         </div>     </div> </div> </div><!-- panel default end --> 

you can using array_slice data per page.

public function index($page = 1) {          $data['title'] = "permissions";          $controller_files = $this->model_extension_permissions->get_installed_permissions('name');           $data['controller_files'] = array();          $files = glob(fcpath . 'application/modules/admin/controllers/*/*.php') ;          $per_page = 5;          $offset = ($page - 1) * $per_page;          $paginatedfiles = array();          if (count($files)) {             $paginatedfiles = array_slice($files, $offset, $per_page, true);         }          if ($paginatedfiles) {              foreach ($paginatedfiles $file) {                  $controller =  basename(strtolower($file), '.php');                  $modules = $this->model_extension_permissions->get_permissions_by_controller($controller);                  $module_data = array();                  foreach ($modules $module) {                     $module_data[] = array(                         'permission_id' => $module['permission_id'],                         'name' => ucwords(str_replace('_', ' ', $controller) . ' &gt; ' . $module['name']),                         'edit' => site_url('admin/extension/permissions/update' .'/'. $controller .'/'. $module['permission_id']),                         'delete' => site_url('admin/extension/permissions/uninstall' .'/'. $controller .'/'. $module['permission_id'])                     );                 }                  $data['controller_files'][] = array(                     'name' => $controller,                     'controller' => $controller,                     'module'    => $module_data,                     'install' => site_url('admin/extension/permissions/install') .'/'.$controller,                     'installed' => in_array($controller, $controller_files)                 );             }         }          $this->load->library('pagination');          $config['base_url'] = base_url()."admin/extension/permissions";         $config['total_rows'] = count($files);         $config['per_page'] = $per_page;         $config['num_links'] = 5;         $config['uri_segment'] = 4;         $config['use_page_numbers'] = true;         $config['full_tag_open'] = '<ul class="pagination pagination-sm">';          $config['full_tag_close'] = '</ul>';          $config['num_tag_open'] = '<li>';          $config['num_tag_close'] = '</li>';          $config['cur_tag_open'] = '<li class="active"><span>';          $config['cur_tag_close'] = '<span class="sr-only">(current)</span></span></li>';          $config['prev_tag_open'] = '<li>';          $config['prev_tag_close'] = '</li>';          $config['next_tag_open'] = '<li>';          $config['next_tag_close'] = '</li>';          $config['first_link'] = '&laquo;';          $config['prev_link'] = '&lsaquo;';          $config['last_link'] = '&raquo;';          $config['next_link'] = '&rsaquo;';          $config['first_tag_open'] = '<li>';          $config['first_tag_close'] = '</li>';          $config['last_tag_open'] = '<li>';          $config['last_tag_close'] = '</li>';          $this->pagination->initialize($config);           $this->parser->parse('template/extension/extension_permissions', $data);     } 

hope useful you.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -