我想將此重新映射爲:index.php/pages/services
此index.php/services
。CodeIgniter路由 - 僅從一個類的URL中刪除類名稱
我該怎麼做?
我嘗試這樣做,但它不工作:
$route['(:any)'] = 'pages/';
== ==修訂
是否有任何動態的方法這種方法?因此,該類中的每個函數都會在url
中沒有classname
而重映射?
我想將此重新映射爲:index.php/pages/services
此index.php/services
。CodeIgniter路由 - 僅從一個類的URL中刪除類名稱
我該怎麼做?
我嘗試這樣做,但它不工作:
$route['(:any)'] = 'pages/';
== ==修訂
是否有任何動態的方法這種方法?因此,該類中的每個函數都會在url
中沒有classname
而重映射?
爲了映射www.domain.com/services
到pages/services
你會是這樣的:
$route['services'] = 'pages/services'
如果要映射www.domain.com/whatever
到pages/whatever
和whatever
有幾個變種,你有幾個控制器,那麼你會怎麼做:
// create rules above this one for all the controllers.
$route['(:any)'] = 'pages/$1'
也就是說,您需要爲所有的控制器/操作創建規則,最後一個應該是一個全面的規則,如上所述。
如果你有太多的控制器和要解決這個特定的路線,將在您的routes.php文件的文件是安全的:
$path = trim($_SERVER['PATH_INFO'], '/');
$toMap = array('services', 'something');
foreach ($toMap as $map) {
if (strpos($path, $map) === 0) {
$route[$map] = 'pages/'.$map;
}
}
注意,而不是$_SERVER['PATH_INFO']
你可能想嘗試$_SERVER['ORIG_PATH_INFO']
或無論哪個組件都能爲您提供完整的網址路徑。
此外,以上未經測試,只是一個例子,讓你開始。
謝謝,我會在一會兒檢查一下,然後會返回一個反饋 – aspirinemaga
'$ route ['services'] ='pages/services';' – Twisted1919
@ Twisted1919 - 你知道是否有任何動態方法,所以'Pages'類中的每個函數都會變成沒有Classname的重映射嗎? – aspirinemaga
你可以嘗試:'$ route ['(:any)'] ='pages/$ 1'',但是這將匹配所有內容。打算用完整的方式發佈答案 – Twisted1919