I am trying to implement pagination in Codeigniter 3 but it always gives a 404 page not found error. I am using htaccess file to hide index.php.
My controller function is
$config = array();
$config['base_url'] = base_url('gallery');
$total_row = $this->gallery_model->record_count();
$config["total_rows"] = $total_row;
$config["per_page"] = 5;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total_row;
$config['uri_segment'] = '4';
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
if($this->uri->segment(2))
{
$page = ($this->uri->segment(2)) ;
}
else
{
$page = 1;
}
$data["results"] = $this->gallery_model->fetch_data($config["per_page"], $page);
HTACCESS is as follows
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /lifeschool-genius/
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
# RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
# RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]
# Enforce NO www
# RewriteCond %{HTTP_HOST} ^www [NC]
# RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
###
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
My Routes file is
$route['(:any)'] = "welcome/$1";
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
I had used the same code before in another project with Codeigniter 2 and it use to work fine. Please let me know what is wrong with this
Any help would be highly appreciated.
Thanks
2
Answers
In codeigniter 3, all(controllers,models,librarues) your file names should start with capital letters.
Also try changing your
htacess
like this,Change these
There is conflict in Your Code
and