基础路由解析
路由分模块解析
kouGrace url 解析规则,如下 :
系统会判断入口文件中 const KG_MULTI_MODULE = true; 这个常量是否为多模块 ,分为单模块和多模块解析!!!单模块路由
md
http://域名/控制器/控制器内方法/gets参数[0]/gets参数[1]/...
如 :
1. http://www.xxxx.com 代表 网站根目录 index 控制器 -> index 方法
|---[ 控制器路径: app/home/index控制器->index方法]
2. http://www.xxxx.com/new/index 代表 网站根目录 news 控制器 -> index 方法
|---[ 控制器路径: app/home/new控制器->index方法]
3. http://www.xxxx.com/new/info/1100.html 代表 网站根目录 news 控制器 -> info 方法
|-[ 控制器路径: app/home/new控制器->info方法->参数:1100]
4. http://www.xxxx.com/admin/user/info/1100/usertest
|-[ 控制器路径: app/home/admin 控制器, user方法 ,后面的都是参数
url 参数 $this->get[0]=1100; $this->get[1]=usertest多模块路由
md
http://域名/模块名(默认home)/控制器/控制器内方法/gets参数[0]/gets参数[1]/...
如 :
1. http://www.xxxx.com
|---[ 控制器路径: app/home/index控制器->index方法]
2. http://www.xxxx.com/new/index
|---[ 控制器路径: app/new模块目录/index控制器->index方法]
3. http://www.xxxx.com/new/info/1100.html
|-[ 控制器路径: app/new模块目录/info控制器->info方法->参数:1100]
4. http://www.xxxx.com/admin/user/info/1100/usertest
|-[ 控制器路径: app/admin模块名称/user控制器, info方法 ,后面的都是参数 ]
url 参数 $this->get[0]=1100; $this->get[1]=usertest控制器及方法常量
开发过程中可以使用 KG_C 及 KG_M 常量获取当前的控制器和方法;
url 参数
经过路由解析后 / 斜杠形式的 url参数统一以数组形式保存在控制器的 $gets 变量内,在控制器内通过 $this->get[数组索引] 方式获取。
php
// url : http://localhost/test/index/grace/10/56;
// 控制器代码
class testController extends kouGrace{
public function index(){
p($this->gets);
echo KG_C.'->'.KG_M;
}
}
// 输出结果
// Array ( [0] => grace [1] => 10 [2] => 56 )
// test->index原生$_GET
php
// url : https://scms.hcoder.net/test/index/1/?key1=1&key2=2
// 控制器代码
class testController extends kouGrace{
public function index(){
p($_GET);
}
}
// 输出结果
// Array ( [key1] => 1 [key2] => 2 )$_POST 也是正常使用哦 (:
