2
嗨,我是在CodeIgniter
新的,我在paginatation一個問題,我用的分頁類,這裏是我的控制器:分頁在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';
建議我這樣做已經都本 –
@Dilipvyas的:嘗試編輯路線 – mrsrinivas
嘗試,但仍無法正常工作,任何人都可以幫我解決這個問題。 。 –