Reputation: 110
Can anyone help me with how I can call a pagination function in a mvc structure?
I links look likes this after the .htaccess
have done its magic:
controller/action/id
Before:
index.php?controller=&action=&id=
What i would really like to do is setting the url like
/controller/px
Where x
is any int value
my .htaccess
:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L,QSA]
I'm hoping for some help or some pointer of any kind would be nice.
Upvotes: 1
Views: 757
Reputation: 785276
You can add this rule before your existing rule:
RewriteRule ^([a-zA-Z]+)/([0-9]+)/?$ index.php?controller=$1&action=&id=&p=$2 [L,QSA]
Upvotes: 1
Reputation: 746
for htaceess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your_folder_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Replace your_folder_name on the third line with your folder name.
if its code ignitor, you need to make some changes in application/config/config.php
change the following lines as below
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
also in autoload in application/config/autoload.php, change to the following line
$autoload['helper'] = array('url');
In Controller
$this->load->library('Pagination');
$config['base_url']=base_url().'controller/function';
$config['total_rows']=$data_count;
$config['per_page']=1;
$config['num_links']=2;
$this->pagination->initialize($config);
While fetching data from database use uri segment and $config['per_page'] as limits
In View
to get the pagination links
echo $this->pagination->create_links();
Upvotes: 0