在我News.php
控制器,我有下面的代碼:當我點擊分頁上的下一個頁面,它會以404錯誤笨
public function index()
{
$data['title'] = 'Database Details';
$config = array();
$config['base_url'] = base_url("news/index");
$config['total_rows'] = $this->news_model->record_count();
$config['per_page'] = 5;
$config['uri_segment'] = 3;
//$config['use_page_numbers'] = TRUE;
// $config['page_query_string'] = TRUE;
$choice = $config["total_rows"]/$config["per_page"];
$config["num_links"] = round($choice);
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
//echo "page--".$page;
$data['user_data'] = $this->news_model->get_details($config['per_page'],$page);
$data['links'] = $this->pagination->create_links();
$this->load->view('templates/header');
echo $this->db->last_query();
$this->load->view('news/index', $data);
$this->load->view('templates/footer');
}
在我News_Model.php
模型,下面的代碼是存在:
public function get_details($limit,$start)
{
//echo "Limit---".$limit."</br>";
//echo "Start---".$start."</br>";
$this->db->limit($limit,$start);
$query = $this->db->get('user_data');
return $query->result_array();
}
我的視圖文件index.php
顯示:
<h3>
<?php echo $title; ?>
</h3>
<table>
<thead>
<th>Name</th>
<th>Address</th>
<th>Email</th>
<th>Mobile</th>
</thead>
<tbody>
<?php
//print_r($user_data);
foreach ($user_data as $user_item):
?>
<tr>
<td><?php echo $user_item["user_name"];?></td>
<td><?php echo $user_item["address"];?></td>
<td><?php echo $user_item["email"];?></td>
<td><?php echo $user_item["mobile"];?></td>
<td><a href="edit?id=<?php echo $user_item["id"];?>">Edit</a></td>
<td><a href="delete?id=<?php echo $user_item["id"];?>">Delete</a></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<p class="pagination"><?php echo $links; ?></p>
在我config.php
:
<?php
$config['base_url'] = 'http://localhost/CodeIgniter-3.0.0/';
$config['index_page'] = 'index.php';
?>
如果刪除$配置[ 'index_page'] = '';我的其他頁面不顯示。
在我route.php
:
<?php
$route['news/(:any)'] = 'news/index/$1'; //explain what does it actually means?
$route['news'] = 'news';
$route['default_controller'] = 'news/create';
$route['(:any)'] ='pages/view/$1';
?>
上面的代碼顯示類似如下:
但是當我點擊page 2
它顯示爲:
請不要建議Link1,Link2和Link3。我已經看過上面的鏈接,但不知道如何得到它:(
請親引導我!
開'config.php'改變'$配置[ 'index_page'] = '的index.php';' – Viral
@viral其已經喜歡你提到的只有 –
@Viral當我的鏈接是這樣的:http://localhost/CodeIgniter-3.0.0/index.php/news/index/2它將顯示。現在我想知道如何獲得index.php之間呢? –