使用CodeIgniter我試圖創建一個鏈接,用戶可以在視圖中單擊以向他們顯示我的數據庫中記錄的詳細信息。使用CodeIgniter的參數鏈接到控制器功能
在ASP.NET MVC3用C#我會做與@Html.ActionLink("Controller", "Action", new { id = item.Id})
這是我的會話控制器指數()函數
public function index()
{
$data['sessions'] = $this->session_model->get_sessions();
$this->load->view('_header');
$this->load->view('session/index', $data);
$this->load->view('_footer');
}
這是該指數查看它加載,我希望能夠點擊鏈接進入,進入()函數
<table>
<th>Session Name</th>
<th>Description</th>
<th>Host</th>
<th></th>
<?php foreach ($sessions as $session_item): ?>
<tr>
<td> <?php echo $session_item['sessionName'] ?> </td>
<td> <?php echo $session_item['sessionDesc'] ?> </td>
<td> <?php echo $session_item['adminName'] ?> </td>
<td> <a id="enterSession" href=<?php echo site_url("session/enter" + $session_item['id']) ?> >Enter</a></td>
</tr>
<?php endforeach ?>
輸入會話指向我的網址「http://192.168.1.36/index.php/1」(如果我的項目的ID是1),而我期望「http://192.168.1.36/index.php/會議/輸入/ 1"
如何,我可以把它稱之爲輸入()函數還會話控制器(如下圖所示)
public function enter($id) {
$this->load->view('_header');
$this->load->view('session/enter');
$this->load->view('_footer');
}
爲了讓url指向正確的位置 - 在href中,嘗試在'「session/enter」'中添加一個尾部的斜槓。或者傳遞一個類似於'$ segments = array('session','enter',$ session_item ['id']);'到'site_url()'的數組。 – jleft 2012-04-21 22:14:19