PHP URL路由類例項

2022-10-06 07:00:14 字數 1477 閱讀 8988

前段時間寫了個關於手機應用的api,一直是用的query_string這種位址,而且還是根據乙個act引數ihkadwr來區分所有的動作,這種讓開發人員看起來比較費眼。本來想改寫為「?c=controller&m=method&type=3&id=1」 這種形式,利用m引數來載入檔案並進行例項化,後來看了sina weibo api 是對位址進行了路由。也決定跟風對位址路由。本來ci框架自己自帶路由效果,但是因為考慮是寫api,想寫的比較純粹一點。

支援預設控制器(index)和方法(index):

複製** **如下:

index.php

index.php/controller

index.ihkadwrphp/controller/method

index.php/controller/method/prarme1/value1

index.php/controller/method/param1/value1/param2/value2.....

具體類如下:

複製** **如下:

<?phpdefine ('module_dir', './classes/');

$app_path= str_replace($_server['document_root'], '', __file__);   

$se_string=str_replace($app_path, '', $_server['request_uri']);    //計算出index.php後面的字段 index.php/controller/methon/id/3

$se_string=trim($se_string,'/');

//echo $se_string.'

';//這裡需要對$se_string進行過濾處理。

$ary_url=array(

'controller'=>'index',

'method'=>'index',

'pramers'=>array()

);//var_dump($ary_url);

$ary_se=ex程式設計客棧plode('/', $se_string);

$se_count=count($ary_se);

//路由控制

if($se_count==1 and $ary_se[0]!='' )else if($se_count>1)else

}}$module_name=$ary_url['controller'];

$module_file=module_dir.$module_name.'.class.php';

//echo $module_file;

$method_name=$ary_url['method'];

if(file_exists($module_file))else

&n程式設計客棧bsp;       }else

}}else

?>

本文標題: php url路由類例項

本文位址:

策略路由例項

如上圖網路拓撲所示,將建立兩條不同的路徑使其接入網路,下面將使用ip命令在三層交換機中建立起兩條路徑,路由來自不同網路的資料報。在三層交換機中建立兩條wan連線,分別標識為wan1 wan2。wan1使用的虛擬網路介面eth0.3,配以靜態ip位址172.16.100.254,經過閘道器172.16...

Vue router路由例項

1.main.js import vue from vue import from mint ui import router from router 註冊全域性元件 vue.component button.name,button eslint disable no new new vue rou...

linux策略路由例項

linux雙網策略路由指令碼例項 雙網要比單網複雜的多。首先安裝linux高階路由包,用裡面的ip命令。apt get install iproute 先建立兩個表 修改 etc iproute2 rt tables如下 加t1自定義編號10 加t2自定義編號20 reserved values 2...