Skip to content

Instantly share code, notes, and snippets.

@Johndllee
Last active August 29, 2015 14:04
Show Gist options
  • Save Johndllee/8c47590ce19be253187c to your computer and use it in GitHub Desktop.
Save Johndllee/8c47590ce19be253187c to your computer and use it in GitHub Desktop.
mycitest/list/index/10 ->error message 404 Page Not Found
<?php
class Lists extends CI_Controller {
private $limit = 10;
public function __construct() {
parent::__construct();
if(!$this->session->userdata('logged_in')){
//Set error
$this->session->set_flashdata('need_login', 'Sorry, you need to be logged in to view the List');
redirect('home/index');
}
// load library
$this->load->library(array('table','form_validation'));
// load helper
$this->load->helper('url');
// load model
$this->load->model('List_model','',TRUE);
}
public function index($offset = 0){
//Get the logged in users id
$user_id = $this->session->userdata('user_id');
// offset
$uri_segment = 3;
$offset = $this->uri->segment($uri_segment);
// load data
$lists = $this->List_model->get_paged_list($this->limit, $offset)->result();
// generate pagination
$this->load->library('pagination');
$config['base_url'] = site_url('list/index/');
$config['total_rows'] = $this->List_model->count_all();
$config['per_page'] = $this->limit;
$config['uri_segment'] = $uri_segment;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['records'] = $this->db->get('lists', $config['per_page'], $this->uri->segment(3));
// generate table data
$data['table'] = $this->table->generate();
//Load view and layout
$data['main_content'] = 'lists/index';
$this->load->view('layouts/main',$data);
}
<?php
class List_model extends CI_Model{
private $tbl= 'lists';
public function get_all_lists($user_id){
$this->db->order_by('create_date', 'asc');
$query = $this->db->get('lists');
return $query->result();
}
function count_all(){
return $this->db->count_all($this->tbl);
}
function get_paged_list($limit = 10, $offset = 0){
$this->db->order_by('id','asc');
return $this->db->get($this->tbl, $limit, $offset);
}
public function get_list($id){
$this->db->select('*');
$this->db->from('lists');
$this->db->where('id',$id);
$query = $this->db->get();
if($query->num_rows() != 1){
return FALSE;
}
return $query->row();
}
I have this error when going to another page in pagination link.
<h1>My Lists</h1>
<?php if($this->session->flashdata('list_created')) : ?>
<?php echo '<p class="text-success">' .$this->session->flashdata('list_created') . '</p>'; ?>
<?php endif; ?>
<?php if($this->session->flashdata('list_deleted')) : ?>
<?php echo '<p class="text-success">' .$this->session->flashdata('list_deleted') . '</p>'; ?>
<?php endif; ?>
<?php if($this->session->flashdata('list_updated')) : ?>
<?php echo '<p class="text-success">' .$this->session->flashdata('list_updated') . '</p>'; ?>
<?php endif; ?>
<p>Table Lists</p>
<!--<ul class="list_items"> -->
<div id="container">
<h3>Pagination</h3>
<?php echo $this->table->generate($records); ?>
<?php echo $pagination; ?>
</div>
<br />
<p>To create a new list - <a href="<?php echo base_url(); ?>lists/add">Click here</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment