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

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

Thank you for advice now all working.

PHP Code:
<?php


class Lists extends MY_Controller {

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

    public function index($sort_by 'name'$sort_order 'asc'$offset 0) {
        $data['title'] = 'Layout List';

        $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')
        );

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

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

        $data['fields'] = array(
            'name' => 'Layout Name',
            'status' => '<div class="text-center">Layout Status</div>',
            'Edit Layout' => '<div class="text-center">Edit Layout</div>'
        );

        $url $this->uri->segment(1) .'/'$this->uri->segment(2) .'/'$this->uri->segment(3) .'/'$this->uri->segment(4);

        if ($url == 'layout/lists' .'/'$sort_by .'/'$sort_order) {
            
            $config
['base_url'] = base_url('layout/lists') .'/'$sort_by .'/'$sort_order;    
            $config
['uri_segment'] = 5;        
            $offset 
$this->uri->segment(5);
            
            $results 
$this->model_layouts->search($this->config->item('admin_limit'), $offset$sort_by$sort_order); 

            foreach($results as $result) {
                $data['results'][] = array(
                    'layout_id' => $result['layout_id'],
                    'name' => $result['name'],
                    'status' => ($result['status']) ? 'Enabled' 'Disabled',
                    'edit' => ($offset) ? anchor('layout/edit' .'/'$sort_by .'/'$sort_order .'/'$offset .'/?layout_id='$result["layout_id"], '<i class="fa fa-pencil fa-2x"></i>', array('class' => 'btn btn-primary')) : anchor('layout/edit' .'/'$sort_by .'/'$sort_order .'/?layout_id='$result["layout_id"], '<i class="fa fa-pencil fa-2x"></i>', array('class' => 'btn btn-primary'))
                );
            }

        } else {

            $config['base_url'] = base_url('layout/lists');
            $config['uri_segment'] = 3;

            $offset $this->uri->segment(3);

            $results $this->model_layouts->search($this->config->item('admin_limit'), $offset$sort_by$sort_order); 

            foreach($results as $result) {
                $data['results'][] = array(
                    'layout_id' => $result['layout_id'],
                    'name' => $result['name'],
                    'status' => ($result['status']) ? 'Enabled' 'Disabled',
                    'edit' => ($offset) ? anchor('layout/edit' .'/'$offset .'/?layout_id='$result["layout_id"], '<i class="fa fa-pencil fa-2x"></i>', array('class' => 'btn btn-primary')) : anchor('layout/edit' .'/?layout_id='$result["layout_id"], '<i class="fa fa-pencil fa-2x"></i>', array('class' => 'btn btn-primary'))
                );
            }
        }

        $config['total_rows'] = $this->model_layouts->count_total();
        $config['per_page'] = $this->config->item('admin_limit');
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['first_link'] = false;
        $config['last_link'] = false;
           $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['prev_link'] = '&laquo';
        $config['prev_tag_open'] = '<li class="prev">';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $this->pagination->initialize($config);
        
        $data
['pagination'] = $this->pagination->create_links();

        $data['sort_by'] = $sort_by;
        $data['sort_order'] = $sort_order;

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

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

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


When I go and click on edit button and then press cancel button now it goes back to the correct page on pagination

On the edit controller I need to use code below

PHP Code:
if ($this->uri->segment(5) == TRUE) {
 
  $data['cancel'] = site_url('layout/lists') .'/'$this->uri->segment(3) .'/'$this->uri->segment(4) .'/'$this->uri->segment(5);
} elseif (
$this->uri->segment(3) == FALSE) {
 
  $data['cancel'] = site_url('layout/lists');
} else {
 
  $data['cancel'] = site_url('layout/lists') .'/'$this->uri->segment(3) .'/'$this->uri->segment(4);



Lists View Table Example


PHP Code:
<table class="table table-bordered table-hover">

<
thead>
<
tr>
<?
php if ($sort_by == 'name') {?>
<td>
<?php echo anchor("layout/lists/name/" . (($sort_order == 'asc' && $sort_by == 'name') ? 'desc' 'asc'),
'Name', array('class' => $sort_order));?>
</td>
<?php } else {?>
<td>
<?php echo anchor("layout/lists/name/" . (($sort_order == 'asc' && $sort_by == 'name') ? 'desc' 'asc'),
'Name');?>
</td>
<?php }?>

<?php if ($sort_by == 'status') {?>
<td class="text-center">
<?php echo anchor("layout/lists/status/" . (($sort_order == 'asc' && $sort_by == 'status') ? 'desc' 'asc'),
'Status', array('class' => $sort_order));?>
</td>
<?php } else { ?>
<td class="text-center">
<?php echo anchor("layout/lists/status/" . (($sort_order == 'asc' && $sort_by == 'status') ? 'desc' 'asc'),
'Status');?>
</td>
<?php }?>

<td class="text-center">Edit Layout</td>
<td class="text-center">Delete Layout</td>

</tr>
</thead>
    <tbody>
    <?php foreach ($results as $result): ?>
        <tr>
            <td><?php echo $result['name'];?></td>
            <td class="text-center"><?php echo $result['status'];?></td>
            <td class="text-center"><?php echo $result['edit'];?></td>
            <td class="text-center"><?php echo $result['delete'];?></td>
        </tr>
    <?php endforeach ?>
    </tbody>
</table> 


Attached Files
.php   Lists.php (Size: 4.12 KB / Downloads: 120)
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
RE: Codeigniter Pagination Will Not Go Back Page - by wolfgang1983 - 10-27-2015, 04:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB