基础路由解析

1. 基础路由解析规则

1.1 phpGrace url 解析规则,如下 : 

http://域名/分组(实际存在的文件夹,空代表根目录分组)/控制器/控制器内方法/gets参数[0]/gets参数[1]/...
如 :
1. http://www.grace.com 代表 网站根目录 index 控制器 -> index 方法
2. http://www.grace.com/new/index 代表 网站根目录 news 控制器 -> index 方法
3. http://www.grace.com/new/info/1100.html 代表 网站根目录 news 控制器 -> info 方法
url 参数 $this->get[0]=1100.html
4. http://www.grace.com/admin/user/info/1100/usertest 代表 /admin 分组目录下 news 控制器 ->info 方法
url 参数 $this->get[0]=1100; $this->get[1]=usertest

1.2 控制器及方法常量

开发过程中可以使用 PG_C 及 PG_M 常量获取当前的控制器和方法;

1.3 url 参数

经过路由解析后 / 斜杠形式的 url参数统一以数组形式保存在控制器的 $gets 变量内,在控制器内通过 $this->get[数组索引] 方式获取。

示例 :

// url : http://localhost/test/index/grace/10/56;
// 控制器代码
class testController extends grace{
    public function index(){
        p($this->gets);
        echo PG_C.'->'.PG_M;
    }
} 
// 输出结果
// Array ( [0] => grace [1] => 10 [2] => 56 )
// test->index

2. 关于 PHP 原生的 $_GET

phpGrace 对 PHP 原生的 $_GET 没有任何影响,您可以和原来一样使用他们 :
// url : https://scms.hcoder.net/test/index/1/?key1=1&key2=2
// 控制器代码
class testController extends grace{
    public function index(){
        p($_GET);
    }
}
// 输出结果
// Array ( [key1] => 1 [key2] => 2 )

$_POST 也是正常使用哦 (: