Pagination does not work 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 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?

+4
source share
3 answers

I see a lot of problems in your code. But 1st place 1st.

Placed

 $this->uri->segment(4) 

in your request in offset.

Update: if you have not done mod_rewrite yet, add 'index.php' to your $config['base_url'] .

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

add your path to the code above.

+5
source

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

in this line you need backslas at the end, for example

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

Update

add this to ur controller in your own way

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

Updating is a crazy idea, although I know less about the code generator.

Switch between your model and controller. Are you sure you call the controller the controller in your code? the same questions for the model.

Update My apologies, your base url should be

 $config['base_url'] = site_url('admin/home/accounts/index/'); 
+3
source

in the 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 pagination ..........

0
source

Source: https://habr.com/ru/post/1393791/


All Articles