I am using codeigniter 2.1.0 and mysql database. in my admin panel I have a page where I want to show all users paginated. But that does not work. after many attempts
here is my updated code
Controller:
function accounts() // controller to view all users { $this -> load -> library('pagination'); $config['base_url'] = site_url('admin/home/accounts/'); $config['total_rows'] = $this->db->get('user')->num_rows(); $config['per_page'] = 2; $config['num_links'] = 2; $config['full_tag_open'] = '<p id="pagination">'; $config['full_tag_close'] = '</p>'; $offset = $this->uri->segment(4,0); $this->pagination->initialize($config); $this->load->model('admin_model'); $data['user_data']=$this->admin_model->all_user($config['per_page'],$offset); $data['links']=$this -> pagination -> create_links(); $data['main_content']='admin/accounts'; $this->load->view('includes/admin/admin_template',$data); }
View:
<?php foreach ($user_data as $data) {?> <?php echo 'Name:' . ' ' ?> <?php echo ($data['name']).'<br/>'; ?> <?php echo 'E-mail:' . ' ' ?> <?php echo ($data['email']).'<br/>'; ?> <br /> <?php } ?> <?php echo $links;?>
Model:
function all_user($per_page,$offset) //shows all uer info { $query = $this->db->get('user', $per_page, $offset); $row=$query->result_array(); return $row; }
and here is the route:
$route['default_controller'] = "site"; $route['404_override'] = ''; $route['admin']='admin/admin';
I used .htaccess mod_rewrite to remove my index.php and $ config ['url_suffix'] = '. html 'to add a .html suffix that makes the url look like this
'http://localhost/project/admin/home/accounts.html'
instead
'http://localhost/project/index.php/admin/home/accounts'
but if i remove url_suffix in my config.php
*/ $config['url_suffix'] = ''; /*
pagination works fine. but i want to use url_suffix
*/ $config['url_suffix'] = '.html'; /*
but if I do, pagination does not work and shows a 404 page error. How can I fix this problem?
source share