Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pagination not working properly in codeigniter 2.1.0 with url_suffix

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 with a paginating view. but it is not working. after trying a lot of things
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 have used the .htaccess mod_rewrite to remove my index.php and the $config['url_suffix']='.html' to add a suffix of .html which makes the url look like this
'http://localhost/project/admin/home/accounts.html'
instead of
'http://localhost/project/index.php/admin/home/accounts'
but if i remove the url_suffix in my config.php

*/

$config['url_suffix'] = '';

/*

the pagination works fine. but i want to use url_suffix

*/

$config['url_suffix'] = '.html';

/*

but if i do so, the pagination doesn't work, and shows 404 page not found error. how do i fix this issue?

like image 636
Shabib Avatar asked Feb 21 '23 16:02

Shabib


2 Answers

I see lots of issues in your code. But 1st thing 1st.

Put

$this->uri->segment(4)

in your query in the offset.

Update: if you haven't done mod_rewrite, then add 'index.php' to your $config['base_url'].

E.g. $config['base_url']=base_url().'index.php/admin/....';

add your path in above code.

like image 103
itachi Avatar answered Mar 02 '23 00:03

itachi


$config['base_url'] = site_url('admin/home/accounts');

in this line you need a backslas at the end like

$config['base_url'] = site_url('admin/home/accounts/');

Update

add this to ur controller in your way

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

Update A crazy idea though i know less about codeigniter.

Switch between your model and controller. Are you sure What you call controller is controller in your code? same ques for model.

Update My apologies, your base url should be

$config['base_url'] = site_url('admin/home/accounts/index/');
like image 25
S. M. Shahinul Islam Avatar answered Mar 01 '23 22:03

S. M. Shahinul Islam