【问题标题】:404 error in codeigniter paginationcodeigniter 分页中的 404 错误
【发布时间】:2014-03-30 01:36:21
【问题描述】:

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

我怀疑它没有读取正确的段,因为我有一个重新路由配置和 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;

    }

我的控制器:

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

【问题讨论】:

    标签: php codeigniter codeigniter-2 codeigniter-url codeigniter-routing


    【解决方案1】:

    正如我所怀疑的,如果没有找到城市,您是在告诉 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;
    

    应该可以的。

    【讨论】:

      【解决方案2】:

      尝试将 base_url 更改为“local/city”,并将 uri_segment 更改为 3。

      【讨论】:

      • @Winterrain 那是一回事。 404 页面。
      • 其实是哪个url抛出404?默认页面 1 是否有效,或者您仅使用 page2、3 等获得 404。
      • 第一页有效,我得到了我想要的限制,但其余的抛出 404。
      • 您是使用 /local/index/ 还是 /local/city/ 访问首页?
      • 那是我的主页,所以我只去localhost/ci。第一页返回我想要的行数,但其他链接只是转到 404。即使我尝试执行 localhost/ci/local/city 它也会抛出 404。我认为它与路由有关
      猜你喜欢
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多