簡體   English   中英

分頁在Codeigniter中不起作用,無法找到404頁面

[英]Pagination not working in codeigniter getting 404 page not found

嗨,我已經在我的網頁中實現了分頁,單擊分頁鏈接時出現錯誤

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

這是目前顯示的網址。

通過添加此格式的代碼來解決

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

更改以下代碼

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

並且

 $config["uri_segment"] = 3;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM