0
我有陣列路由:反向的preg_replace - 路由器
$route = array(
'/home/news/([0-9])'=>'/home/news/id/$1'
);
我有腳本檢查請求&的Valide。所以,我可以運行:
http://mysite.com/home/news/id/4 (run: controller: home, action: news, param id: 4 -> this is defaults)
和
http://mysite.com/home/news/4 (run: controller: home, action: news, param id: 4 -> look route array [up])
腳本:
$request = '/home/news/id/10'; //example
foreach($route as $r => $key) {
$r = str_replace('/', '\\/', $r);
if(preg_match('/^'.$r.'$/',$request)) {
$request = preg_replace('/^'.$r.'$/i',$key,$request);
break;
}
所以我想現在翻轉所有:
function createUrl($array) {
//search in route value and if is ok return key array
}
例子:
echo createUrl(array('controller'=>'home','action'=>'news','id'=>4)); //if not exists in route return: /home/news/id/4 but if exists reutnr /home/news/4
我爲我的英語很抱歉:d
所以基本上我們必須在這裏猜測這個問題以及'createurl()'中的任何內容嗎? – PeeHaa
請您在請求中更清楚,我不明白這個問題。 –