2011-02-27 152 views
0

我目前的發展是使用CodeIgniter,當我嘗試傳遞一些參數到我的主控制器的索引函數時,它返回我404 errorCodeIgniter路由問題與控制器的索引功能

http://localhost/gis/1 -> 404 ERROR 
http://localhost/gis/home/1 -> 404 ERROR 

其實我route.php文件中有這樣的路線:

$route['default_controller'] = "home";  

$route['home/([:num])'] = 'home/index/$1'; 

.htaccess文件是這樣的(從this post帶走的index.php從CI網址):

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    RewriteCond %{REQUEST_URI} ^application.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 

而我的config.php檔案:

$config['base_url'] = "http://localhost/gis"; 

$config['index_page'] = ""; 

我在做什麼錯?謝謝!

+0

「routes.php」中的默認控制器是什麼? – Sarfraz 2011-02-27 11:23:49

+0

@Sarfraz我編輯我自己的問題 – 2011-02-27 11:30:54

回答

2

更新:

報價OP:

的.htaccess無罪。問題 是我的路線需要是 $ route ['home /(:num)'] = ...我加了 括號和所有作品。


不是:

$route['home/([:num])'] = 'home/index/$1'; 

嘗試指定這樣的:

$route['home/:num'] = 'home/index/$1'; 

還要確保從application/config/routes.php,默認控制器設置爲home

$route['default_controller'] = 'home'; 
+0

感謝您的快速回答。我試過你說的話,但它對我沒有用。如果我嘗試在我的主控制器索引功能中打印參數,請始終打印'$ 1'。你可以幫我嗎? – 2011-02-27 11:32:46

+0

@Fran維羅納:嘗試禁用.htaccess文件來檢查它是否有問題。 – Sarfraz 2011-02-27 11:35:42

+0

htaccess無罪。問題是我的路線需要$ route ['home /(:num)'] = ...我添加了括號和所有作品。你可以編輯自己的答案來添加這個?非常感謝Sarfraz。 – 2011-02-27 11:39:16