gpt4 book ai didi

php - codeigniter 分页中的 404 错误

转载 作者:搜寻专家 更新时间:2023-10-31 21:34:43 25 4
gpt4 key购买 nike

我看到很多这样的问题,但我无法解决问题。

我怀疑它没有读取正确的段,因为我有一个重新路由配置和 htaccess 来删除索引页。

代码抛出 404 页面。

这是我的模型:

    public function get_city_reviews($city_id,$limit,$offset) {

$list = array();

$this->db->from('biz');

$this->db->where('city_id',$city_id);

$this->db->order_by('created_at','desc');

$this->db->limit($limit,$offset);

$query = $this->db->get();
foreach($query->result() as $row) {

$list[] = $row;

}

return $list;

}

我的 Controller :

         $slug = $this->uri->segment(1,'');
if($slug)
{
$this->load->model('catsAndCities','cc');
$this->cc->set_table_name('city');
$city = $this->cc->get($slug,'slug');

if(!$city || $city->parent_id != 0)
{
show_404();
}
else
{
$this->tank_auth->set_user_city($city);
}
}
else
{
$city = $this->tank_auth->get_user_city();
}
$this->load->library('pagination');

$config = array();

$base_url ="local/index/";

$config["base_url"] = site_url().$base_url;

$config["total_rows"] = $this->bizs->record_count();

$config["per_page"] = 5;

$config["uri_segment"] = 4;

$config['full_tag_open'] = '<p class="pageBar">';

$config['full_tag_close'] = '</p>';

$config['num_links'] =2;

$config['anchor_class'] = 'class="page-num" ';

$this->pagination->initialize($config);

$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;

$data["results"] = $this->bizs->get_city_reviews($city->id,$config["per_page"],
$page);

$data["pagination_links"] = $this->pagination->create_links();

$data['reviews'] = $data["results"];

$this->load->view('local/index',$data);

我的看法:

    <div id="pagination-container">
<div class="pagination">
<ul>

<?=$pagination_links?>

</ul>
</div>

这是我的路线:

   $route['default_controller'] = "local/city";
$route['[0-9a-zA-Z\-_]+'] = "local/city";
$route['scaffolding_trigger'] = "";

这是我的 htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On

#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>


ErrorDocument 404 /index.php
</IfModule>

最佳答案

正如我所怀疑的,如果没有找到城市,您是在告诉 CI 查找 404 页面。尝试对此发表评论:或找到一种解决方法。

     if(!$city || $city->parent_id != 0)
{
show_404();
}
else
{
$this->tank_auth->set_user_city($city);
}

然后改变

   $base_url ="local/index/";

   $base_url ="";

而你的分割为 1

  $config["uri_segment"] = 1;

应该这样做。

关于php - codeigniter 分页中的 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22739246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com