2012-04-21 63 views
1

使用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'); 
    } 
+0

爲了讓url指向正確的位置 - 在href中,嘗試在'「session/enter」'中添加一個尾部的斜槓。或者傳遞一個類似於'$ segments = array('session','enter',$ session_item ['id']);'到'site_url()'的數組。 – jleft 2012-04-21 22:14:19

回答

0

似乎是在字符串連接一個錯字任何想法在你的PHP代碼中。也許它會工作使用:

site_url("session/enter" . $session_item['id']) 

...而不是兩個字符串之間的+跡象。

關於第二個問題 - 它看起來是正確的。它是否未能調用session控制器的enter()函數通過$id作爲參數(假設URL是正確的)?

+0

輝煌,謝謝。我確實需要將'+'改爲'.'哦,並添加一個/字符。所以這現在可以:) '​​ >Enter' – Leanne182x 2012-04-21 22:25:46

相關問題