codeigniter 404中的分页错误

时间:2013-04-23 12:04:08

标签: php codeigniter pagination

控制器文件:此处的功能索引

      public function index()
      {
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->model('register_model');
        $this->load->library("pagination");
        $config = array();
        $config["base_url"] = base_url()."register";
        $config["total_rows"] = $this->register_model->record_count();
        $config["per_page"] = 5;
        $config["uri_segment"] = 3;

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

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["result"] = $this->register_model->fetch_logs($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();            
        $this->load->view('register',$data);            
      }

这是我的模型功能

     public function view()
     {
      $query = $this->db->query("select * from user_login");
       return $query->result_array();
      }

    public function record_count() 
    {
       return $this->db->count_all("user_login");
    }

    public function fetch_logs($limit, $start) 
    {
       $this->db->limit($limit, $start);
       $query = $this->db->get("user_login");

       if ($query->num_rows() > 0) {
           foreach ($query->result() as $row) {
              $data[] = $row;
           }
           return $data;
        }
        return false;
      }

这是我的观看代码         

    <form method="post" accept-charset="utf-8" action="<?php echo base_url(); ?>/register/create" class="myform" id="myform" />

    <div style="text-align:left;"><h1>User Registration</h1></div>
        <table width="488" border="0">
          <tr>
            <td colspan="3">User
              <input name="user_name" type="text" size="40" /></td>
          </tr>
          <tr>
            <td colspan="3">Pass
              <input name="password" type="password" size="40" /></td>
          </tr>
          <tr>
            <td width="278" align="right"><input name="submit" type="submit" value="ADD"  class="big_btn"/></td>
            <td width="148" align="center">&nbsp;</td>
            <td width="48" align="center">&nbsp;</td>
          </tr>
      </table>
        <p>&nbsp;</p>
            <table width="679" border="1" cellpadding="3" cellspacing="0">

        <tr><th width="202" align="center">User</th>    
          <th width="319" align="center">Password</th>
          <th colspan="2" align="center">Action</th>
        <?php 
        foreach ($result as $row)
      {
      ?>
      <tr>
      <td height="32" align="center"><?php echo $row->user;?>   </td>
      <td align="center"><?php echo md5($row->pwd);?></td>
      <td width="56" align="center"><a href="<?php echo base_url();?>/register/delete/<?php echo $row->id;?>">
       <input name="delete" type="button" id="delete" value="x" class="del_btn">

      </a></td>
      <td width="68" align="center"><?php 
    $atts = array(
                  'width'      => '700',
                  'height'     => '300',
                  'scrollbars' => 'no',
                  'status'     => 'no',
                  'resizable'  => 'yes',
                  'screenx'    => '600',
                  'screeny'    => '150'
                );
    echo anchor_popup(base_url().'/register/viewmore/'.$row->id, '<input name="view" type="button" id="view" value="" class="view_btn">', $atts);
    ?></td>
      </tr>
    <?php  
      }

        ?>

      </table>

    </form>
    </div>   <p><?php echo $links; ?></p>  

在这里,我可以看到分页链接,但在我点击链接后,它给出了404 Page Not Found错误 任何人都可以检查并回复??

4 个答案:

答案 0 :(得分:0)

更改此

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

到这个

$config["base_url"] = base_url('register'); // or you can use site_url('register');

答案 1 :(得分:0)

如果您的上述控制器是注册控制器,那么您可以

  $config["base_url"] = site_url("register"); //this will call the index function of register contoller

答案 2 :(得分:0)

public function index() {
    $this->load->helper ( 'url' );
    $this->load->helper ( 'form' );
    $this->load->model ( 'register_model' );
    $this->load->library ( "pagination" );
    $config = array ();
    $config ["base_url"] = base_url ( 'register/index/' );
    $config ["total_rows"] = $this->register_model->record_count ();
    $config ["per_page"] = 5;
    $config ["uri_segment"] = 3;
    $this->pagination->initialize ( $config );
    $page = ($this->uri->segment ( 3 )) ? $this->uri->segment ( 3 ) : 0;
    $data ["result"] = $this->register_model->fetch_logs ( $config ["per_page"], $page );
    $data ["links"] = $this->pagination->create_links ();
    $this->load->view ( 'register', $data );
}

答案 3 :(得分:0)

我认为这是问题尝试这个 像

$config['base_url'] = site_url('register/index/');