我正在尝试在Codeigniter 3中实现分页,但它始终提供404页面未找到错误。我正在使用htaccess文件来隐藏index.php。
我的控制器功能是
$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如下
<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>
我的路线文件是
$route['(:any)'] = "welcome/$1";
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
我之前在使用Codeigniter 2的另一个项目中使用了相同的代码,并且它可以正常工作。请告诉我这个
有什么问题任何帮助都将受到高度赞赏。
由于
答案 0 :(得分:0)
在codeigniter 3中,所有(控制器,模型,图书馆)文件名都应以大写字母开头。
也可以尝试像这样更改htacess
,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
答案 1 :(得分:0)
更改这些
$config['base_url'] = base_url().'gallery';
$config['uri_segment'] = '1';
if($this->uri->segment(1))
{
$page = ($this->uri->segment(1)) ;
}
您的代码存在冲突
$config['uri_segment'] = '4';
和
if($this->uri->segment(2))
{
$page = ($this->uri->segment(2)) ;
}