2015-04-24 30 views
0

如何在CodeIgniter中使用路由?我試過但沒有結果。這是我的觀點:如何在CodeIgniter中使用路由

<a href="/survey/index.php/index/student_surveys/1/" class='btn btn-success'> 1 </a> 
 
<a href='/survey/index.php/index/student_surveys/2/'class='btn btn-success'> 2 </a> 
 
<a href='/survey/index.php/index/student_surveys/3/'class='btn btn-success'> 3 </a>

我試着用這樣的:

$route['survey/index.php/index/student_surveys/1/'] = 'index/student_surveys/1/'; 
 
$route['survey/index.php/index/student_surveys/2/'] = 'index/student_surveys/1/';

但是,當我改變鏈路測試,它不會改變。它只適用於我的鏈接而不是路由。我的控制器:

public function student_surveys() { 
 
$this->form_validation->set_rules('teacher', 'Teacher', 'required'); 
 
     $this->form_validation->set_rules('subject', 'Subject', 'required|callback_subject'); 
 
     if ($this->form_validation->run()==FALSE) 
 
     { 
 
      $this->student_surveys_show(); 
 
     } 
 
     else 
 
     { 
 
$this->user_model->add_teacher_subject(); 
 
redirect('/index/survey_show/' . $survey_id); 
 
      }    
 
      
 
     } 
 

 

+0

你有沒有嘗試過,'$這個 - >負載>視圖( 'survey_show',$ survey_id,TRUE);' ? –

+0

我想使用路線。 :) –

回答

3

試試這個

$route['confirm_registration/(:any)']= "login/confirm_registration/$1"; 
+0

是的,但我有3個鏈接,它應該重定向到「登錄/ confirm_registration/$ 1」;如果$ route ['confirm_registration/1'],「login/confirm_registration/$ 2」;如果'confirm_registration/2' –

+1

不,你不需要3美元或4美元,增加1美元,它會取代你的計數 –