4
votes

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?

3
Whats the url when you click on next page - Sabari
Will it work if you take localhost/project/admin/home/accounts.php/2 - Sabari
@sabari,no it won't work.in the url localhost is the server project is the folder that contains whole project, admin is a subdomain containing the admin controller, home is the class and accounts is the function of the home class.the '.html' is just an extra suffix that codeigniter provides if i configure it to.it doesn't matter what the sufffix is '.html'/'.php'/'.asp' or none, the functionality remains the same. - Shabib
Can you paste your router config - Sabari

3 Answers

5
votes

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.

3
votes

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

in system -> Pagination.php file (default settings)

class CI_Pagination {

var $base_url           = ''; // The page we are linking to
var $prefix             = ''; // A custom prefix added to the path.
var $suffix             = ''; // A custom suffix added to the path.
.
.
}

$config['suffix'] ="example"

Url_suffix for your pagination ..........