2

嗨,我是CodeIgniter新手,分页有问题,我使用了分页类,这是我的控制器:

 public function user($page='user')
        {
            $this->load->helper('url');
            $this->load->library('pagination');
            if ( ! file_exists('application/views/admin/'.$page.'.php'))
            {
                // Whoops, we don't have a page for that!
                show_404();
            }
            //$data['user'] = $this->user->get_user($config["per_page"], $page);
            //$config = array();
            $config["base_url"] = base_url().'index.php/admin/user/';
            $config["total_rows"] = $this->user->record_count();
            $config["per_page"] = 5;
            $config["num_link"] = 3;
            $config['uri_segment'] = '5';
            $config['full_tag_open']='<ul>';
            $config['full_tag_close']='</ul>';
            $config['prev_link'] = 'Prev';
            $config['prev_tag_open'] = '<li>';
            $config['prev_tag_close'] = '</li>';
            $config['next_link'] = 'Next';
            $config['next_tag_open'] = '<li>';
            $config['next_tag_close'] = '</li>';
            $config['cur_tag_open'] = '<li class="current1">';
            $config['cur_tag_close'] = '</li>';
            $config['num_tag_open'] = '<li>';
            $config['num_tag_close'] = '</li>';
            $this->pagination->initialize($config);
            $offset = $this->uri->segment(5);
            //$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0 ;
            //print_r($this->user->fetch_countries($config["per_page"],$this->uri->segment(3)));
            $data['user'] = $this->user->fetch_countries($config["per_page"],$offset);
            //$data['total_rows'] = $this->user->record_count($config["per_page"],$this->uri->segment(3));
            $data["links"] = $this->pagination->create_links();
            //print_r($data);
            //die();
            $data['base'] = $this->config->item('base_url');
            $data['css'] = $this->config->item('css');
            $this->load->view('admin/header', $data);
            $this->load->view('admin/'.$page,$data);
            $this->load->view('admin/footer',$data);
        }

型号代码:

   public function record_count() {
        return $this->db->count_all("user");
     }
     public function fetch_countries($limit, $start) {
        $query = $this->db->get("user",$limit, $start);
            return $query->result_array();

     }

以及查看代码:

<?php foreach ($user as $user_detail): ?>
        <tr class="gray_line2">
            <td class="sname2"><?php echo $i ?></td>
            <td class="sname2"><?php echo $user_detail['name'] ?></td>
            <td class="sname2"><?php echo $user_detail['username'] ?></td>
            <td class="sname2"><?php echo $user_detail['email'] ?></td>
            <td class="sname2"><?php echo $user_detail['contact'] ?></td>
            <td class="sname2"><?php echo $user_detail['dob'] ?></td>
            <td><div class="action">
                <ul>
                    <li><a href="user_detail?id=<?php echo $user_detail['id'] ?>" class="link" title="Details"><img src="<?php echo base_url();?>images/detail.png" class="left"></a></li>
                    <li><a href="user_edit?id=<?php echo $user_detail['id'] ?>" class="link" title="Edit"><img src="<?php echo base_url();?>images/edit.png" class="left"></a></li>
                    <li><a href="user_delete?id=<?php echo $user_detail['id'] ?>" class="link" title="Delete"><img src="<?php echo base_url();?>images/cross.png" class="left"></a></li>
                </ul>
            </div></td>
        </tr>
        <?php 
         endforeach  ?>     
    </table>
</div>
<div class="pagi">
<div class="pagination">
<?php echo $links; ?>

这是我得到的

这是浏览器视图,只有一页显示,当我点击第二页的链接时,出现 404 错误。我正在使用以下路线

$route['admin/(:num)/(:any)'] = 'admin/user/$1';
Or
$route['admin/(:num)/(:any)/(:num)'] = 'admin/user/$1/$2/$3';
4

1 回答 1

5

一旦检查

$config['uri_segment'] = 4;

或者

像这样改变方法

public function user(){
  //Your code
}

在你的控制器中..

路线

$route['admin/user/(:any)'] = 'admin/user/$1';

编辑

由 Dilipvyas 推荐

$route['admin/:num'] = 'admin/user/$1';
于 2013-03-30T12:27:32.097 回答