【问题标题】:Pagination not working in codeigniter getting 404 page not found分页在codeigniter中不起作用,找不到404页面
【发布时间】:2018-02-02 05:39:19
【问题描述】:

您好,我已经在我的网页中实现了分页,点击分页链接时出现错误

404 页面未找到

找不到您请求的页面。

控制器:

class Blogs extends CI_Controller
{
function __construct()
    {
        parent::__construct();
        $this->load->library('session');
        $this->load->library('form_validation');
        $this->load->library("pagination");
        $this->load->model('blogs_model');
        if($this->session->userdata('admin_logged_in')){
            $this->data['admin_details'] = $this->session->userdata('admin_logged_in');
        }
        else{
            redirect('welcome');
        }
    }

function index()
    {   
    $config = array();
    $config["base_url"] = base_url() . "blogs/index";
    $config["total_rows"] = $this->blogs_model->record_count();
    $config["per_page"] = 11;
    $config["uri_segment"] = 4;
    $this->pagination->initialize($config);
    $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
     $data['records'] = $this->blogs_model->get_blogs($config["per_page"], $page);          
     $data["links"] = $this->pagination->create_links();
     $data['mainpage']='blogs';
     $data['mode']='all';
     $this->load->view('templates/template',$data);
    }
    }

型号:

function get_blogs($limit, $start)
{
    $this->db->limit($limit, $start);
    $this->db->Select('blogs.*');
    $this->db->From('blogs');
    $this->db->where(array('blogs.status'=>1));
    $this->db->order_by("date", "desc");
    $q=$this->db->get();
    if($q->num_rows()>0)      
    {       
        return $q->result();
    }
    else
    {
        return false;
    }
}

查看:

    <div id="main">         
        <div class="full_w">
            <div class="h_title">
                <div class="lefttitle fl">
                    Blogs
                </div>
                <div class="rightbutton fr">
                    <a class="button add" href="<?php echo site_url();?>/blogs/add">Add </a>
                    <a class="button add" href="<?php echo site_url();?>/category">Category </a>
                    <a class="button del" href="<?php echo site_url();?>/blogs/deactivated">Deactivated Blogs</a>                       
                </div>
            </div>
            <table>
                <thead>
                    <tr>
                        <th scope="col">Featured Blogs</th>
                        <th scope="col">S.No</th>
                        <th scope="col">Blog Title</th>
                        <th scope="col">Author</th>
                        <th scope="col">Comments</th>                            
                        <th scope="col">Date</th>
                        <th scope="col">Hits</th>
                        <th scope="col" style="width: 65px;">Modify</th>
                    </tr>
                </thead>

                <tbody>

                <?php if(isset($records) && is_array($records) && count($records)>0): ?>    
                <?php  $i=0;foreach($records as $r):$i++;?>     
                    <tr>
                        <td><input type="checkbox" name="checkbox" value="<?php echo $r->blog_id;?>"></td>                          
                        <td class="align-center"><?php echo $i;?></td>
                        <td><?php echo $r->blog_title;?></td>
                        <td><?php echo $r->username;?></td>
                        <td><span data-plugin="comment-count"><?php echo $comments;?></span></td>
                        <td><?php echo $r->date;?></td>
                        <td><?php echo $r->ne_views;?></td>
                        <td>
                            <a href="<?php echo site_url();?>/blogs/edit/<?php echo $r ->blog_id ;?>" class="table-icon edit" title="Edit"></a>
                            <a href="<?php echo site_url();?>/blogs/delete/<?php echo $r ->blog_id ;?>"  onclick="return confirm('Are you sure to delete');" class="table-icon delete" title="Delete"></a>
                        </td>
                    </tr>

                <?php endforeach ;endif;?>

                </tbody>
            </table>
            <p><?php echo $links; ?></p>
            <button id="someButton">Activate</button>
</button>
        </div>
    </div>
    <div class="clear"></div>

是否有任何更改需要做不知道为什么它显示为404页面未找到。

它将网址显示为:staging.website.com/admin/index.php/blogs

这是目前显示的网址。

【问题讨论】:

  • 你可能需要在 routes.php sitepoint.com/pagination-with-codeigniter 中设置一些路由,你也不需要在 base url $config["base_url"] = base_url('blogs'); 中使用索引其他功能是但不是索引。
  • @wolfgang1983 听不懂你在说什么

标签: php codeigniter pagination


【解决方案1】:

通过添加这种格式的代码解决

$config = array();
     $config["base_url"] = base_url("index.php/blogs/index");

【讨论】:

    【解决方案2】:

    修改以下代码

     $config["base_url"] = base_url("blogs/index");
     $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    

    还有

     $config["uri_segment"] = 3;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-14
      • 2019-12-02
      • 1970-01-01
      • 2015-12-19
      • 1970-01-01
      • 2016-02-21
      • 2016-11-14
      相关资源
      最近更新 更多