Welcome Guest, Not a member yet? Register   Sign In
[Solved] Codeigniter Pagination Will Not Go Back Page
#1

(This post was last modified: 10-28-2015, 01:37 AM by wolfgang1983.)

I have got a List controller where I can sort the table thead links all working fine.

The problem is when I click on a pagination link and go to that page I click on it will not let me click and go back to a different page.

$this->uri->segmet(5); is where I think issue is because it is the page number. Every thing else works fine it just will not let me go back to a different page when uri->segment(5) active.


PHP Code:
<?php

class Lists extends MY_Controller {

    public function 
__construct() {
        
parent::__construct();
        
$this->load->library('paginations');
        
$this->load->model('layouts/model_layouts');
    }

    public function 
index() {
        
$data['title'] = 'Layout List';

        if (
$this->uri->segment(3)) {
            
$sort $this->uri->segment(3);
        } else {
            
$sort '/name';
        }

        if (
$this->uri->segment(4)) {
            
$order $this->uri->segment(4);
        } else {
            
$order '/asc';
        }

        
$url '';

        if (
$this->uri->segment(3)) {
            
$url .= '/'$this->uri->segment(3);
        }

        if (
$this->uri->segment(4)) {
            
$url .= '/'$this->uri->segment(4);
        }

 
               // Problem Here

        
if ($this->uri->segment(5)) {
            
$url .= '/'$this->uri->segment(5);
        } 

        
$data['breadcrumbs'] = array();

        
$data['breadcrumbs'][] = array(
            
'text' => '<i class="fa fa-home"></i> Home',
            
'href' => site_url('common/dashboard')
        );

        
$data['breadcrumbs'][] = array(
            
'text' => 'Layout List',
            
'href' => site_url('layout/lists' $url)
        );

        
$data['add'] = site_url('layout/add') . $url;

 
               $data['layouts'] = array();

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

        if (
$this->uri->segment(3) == 'name') {
            
$start = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
        } else {
            
$start = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        }

        if (
$this->uri->segment(3) == 'status') {
            
$start = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
        } else {
            
$start = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        }

        
$config['base_url'] = base_url('layout/lists' $url);
        
$config['total_rows'] = $this->model_layouts->count_total();
        
$config['per_page'] = $this->config->item('admin_limit');

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

        
$data['pagination'] = $this->pagination->create_links();

        
$results $this->model_layouts->get_layouts($config['per_page'], $start); 

        foreach (
$results as $result) {
            
$data['layouts'][] = array(
                
'layout_id' => $result['layout_id'],
                
'name' => $result['name'],
                
'status' => ($result['status'] ? '<div class="label label-success">Enabled</div>' '<div class="label label-warning">Disabled</div>'),
                
'edit' => ($this->uri->segment(3)) ? site_url('layout/edit' $url .'/'$result['layout_id']) : site_url('layout/edit/' $result['layout_id']),
                
'delete' => ($this->uri->segment(3)) ? site_url('layout/delete' $url .'/'$result['layout_id']) : site_url('layout/delete/' $result['layout_id']),
            );
        }

        
$success_flash_data $this->session->flashdata('success');

        if (isset(
$success_flash_data)) {
            
$data['success'] = $success_flash_data;

            unset(
$success_flash_data);
        } else {
            
$data['success'] = '';
        }

        
// Link for sort name must be left here

        
$url '';

        if (
$order == 'asc') {
            
$url .= '/desc';
        } else {
            
$url .= '/asc';
        }

        if (
$this->input->get('page')) {
            
$url .= $this->input->get('page');
        }

        
$data['sort_name'] = site_url('layout/lists/name') . $url;
        
$data['sort_status'] = site_url('layout/lists/status') . $url;

        
$url '';

        if (
$this->uri->segment(3)) {
            
$url .= '/'$this->uri->segment(3);
        }

        if (
$this->uri->segment(4)) {
            
$url .= '/'$this->uri->segment(4);
        }

        
$text_pagination 'Showing Rows %d to %d out of %d (%d Pages)';

        
//$data['results'] = sprintf($text_pagination, ($this->model_layouts->count_total()) ? (($page - 1) * $this->config->item('admin_limit')) + 1 : 0, ((($page - 1) * $this->config->item('admin_limit')) > ($this->model_layouts->count_total() - $this->config->item('admin_limit'))) ? $this->model_layouts->count_total() : ((($page - 1) * $this->config->item('admin_limit')) + $this->config->item('admin_limit')), $this->model_layouts->count_total(), ceil($this->model_layouts->count_total() / $this->config->item('admin_limit')));

        
$data['sort'] = $sort;
        
$data['order'] = $order;

        
$data['admin_page'] = 'template/layout/' strtolower(__CLASS__) . '_view';
        
$this->load->view('template/common/template'$data);
    }


Any suggestion and example world be great

I have been reading this http://www.codeigniter.com/user_guide/li...ation.html

I also have attached the controller

Attached Files
.php   Lists.php (Size: 4.01 KB / Downloads: 186)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
[Solved] Codeigniter Pagination Will Not Go Back Page - by wolfgang1983 - 10-27-2015, 03:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB