2012-02-01 121 views
1

我有一類叫做評論和裏面我有3個功能叫做__construct,指數和getComments笨路由索引

Class comment extends CI_Controller 
{ 
    public function __construct(){ 
     parent::__construct(); 
    } 

    public function index($comment_id){ 
     echo $comment_id; 
    } 

    public function getComments(){ 
     //do stuff to get comments and print them to screen 
    } 
} 

也是在我的路徑文件夾我添加了一個新的途徑

$route['comment/(:any)'] = "comment/index/$1"; 

所以當我去mysite.com/comment/123131313123

回聲評論ID BU t當我做一個Ajax調用getComments()函數在同一類它不會工作,而是它會告訴我單詞「getComments

我怎麼能確保當我去直接索引函數它會顯示我的參數,也能夠做一個Ajax調用,而沒有任何其他功能的問題?

謝謝。

+0

你是怎麼做ajax調用?什麼是你使用的網址? – Matthew 2012-02-01 17:04:27

+0

即時通訊使用mysite.com/comment/getComments - 我沒有添加我用於ajax調用的php代碼,因爲它太多了...如果我刪除索引和路由所有的ajax調用工作正常。 – fxuser 2012-02-01 17:13:03

回答

2

mysite.com/comment/getComments是越來越符合您的路線

您需要它來使另一條路線,其中明確符合您的阿賈克斯行動

$route['comment/getComments'] = "comment/getComments"; 
$route['comment/(:any)'] = "comment/index/$1"; 

路由在它們被定義的順序運行。

+1

作品完美... – fxuser 2012-02-01 18:04:59