~~~ <?php namespace php\lib; class route { public $controller;//控制器 public $action;//方法 public function __construct() { /* *****.com/index.php/index/index 1.隐藏index.php *****.com/index/index 2.获取url参数部分 3.返回对应的控制器和方法 */ if (isset( $_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI']!='/' ) { $path=$_SERVER['REQUEST_URI']; $patharr=explode('/',trim($path,'/')); if ($patharr['0']=='index.php') { unset($patharr['0']); if (isset($patharr['1'])) { $this->controller=$patharr['1']; } unset($patharr['1']); if (isset($patharr['2'])) { $this->action=$patharr['2']; } unset($patharr['2']); $count=count($patharr)+3; $i=3; while ( $i< $count) { if ($patharr[$i + 1]) { $_GET[$patharr[$i]]=$patharr[$i + 1]; } $i=$i+2; } return $_GET; // print_r($_GET); }else{ if (isset($patharr['0'])) { $this->controller=$patharr['0']; } unset($patharr['0']); if (isset($patharr['1'])) { $this->action=$patharr['1']; } unset($patharr['1']); } }else{ $this->controller='index'; $this->action='index'; } } } ~~~