2012-01-11 31 views
2

我有點棘手,我甚至不確定CI是否被設計爲以這種方式工作。CI靜態D/C/M路由和URI參數

我有一個子域,讓稱之爲test.warren.com

test.warren.com指向一個CI的index.php,這是從在訪問沃倫當被加載在主index.php的分離。 COM。

的test.warren.com的index.php文件已經靜態路由定義,如按照CI評論

/* 
* -------------------------------------------------------------------- 
* DEFAULT CONTROLLER 
* -------------------------------------------------------------------- 
* 
* Normally you will set your default controller in the routes.php file. 
* You can, however, force a custom routing by hard-coding a 
* specific controller class/function here. For most applications, you 
* WILL NOT set your routing here, but it's an option for those 
* special instances where you might want to override the standard 
* routing in a specific front controller that shares a common CI installation. 
* 
* IMPORTANT: If you set the routing here, NO OTHER controller will be 
* callable. In essence, this preference limits your application to ONE 
* specific controller. Leave the function name blank if you need 
* to call functions dynamically via the URI. 
* 
* Un-comment the $routing array below to use this feature 
* 
*/ 
    // The directory name, relative to the "controllers" folder. Leave blank 
    // if your controller is not in a sub-folder within the "controllers" folder 
    $routing['directory'] = 'subdir'; 

    // The controller class file name. Example: Mycontroller 
    $routing['controller'] = 'testcontroller'; 

    // The controller function you wish to be called. 
    $routing['function'] = 'testmethod'; 

現在,這一切工作的花花公子 - 我有一個方法的網站。沒有別的東西可以訪問只有那種方法。如果我去test.warren.com - 我會得到testmethod()執行的任何內容。現在

,我不能做的部分 - 是傳中URI PARAMS EG:test.warren.com/param1/param2/param3 --- 404

至於我可以調試的原因,這不起作用是因爲當初始化路由器類時,它會嘗試檢查'param1'是否是控制器類或目錄;這符合標準CI配置所期望的。然後404s出來。

我想我可以通過編輯index.php底部加載的主核心/ CodeIgniter.php來解決它;但是我很猶豫,因爲這個CI安裝有多個站點安裝。

CI是v2.0.3

有誰知道這是可能的嗎?

+0

你是否試圖直接在你的域名後面傳遞參數,就像你在例子test.warren.com/param1/param2/param3中提到的那樣? – 2012-02-29 14:26:09

回答

0

如果您以這種方式使用「默認路線」,則需要設置第二條路線以通過參數。

$route['(:any)/(:any)/(:any)'] = 'controller/action/$1/$2/$3'; 

這個「應該」的工作,以匹配它,你就必須通過三個參數,如果你不通過三門,它會恢復到默認的控制器或404(如果只有一個或兩個通過)。

希望有幫助嗎?