yaf 路由协议配置测试
来源:互联网 发布:网络接口图片 编辑:程序博客网 时间:2024/04/30 05:04
好久没写博客了,最近老板让我转到php部门,要学习Yaf,它的路由机制真心难理解,主要是官方文档没有写清楚,网上也没有太多的实用的文档。特地写一篇博客供大家参考。各种路由协议的原理请大家参考http://www.laruence.com/manual/yaf.routes.static.html#N20845,这里不再重复,直接说用法。
注:假设我们的主机名为http://www.domain.com
默认路由协议
在使用这个协议时一定要在url中写上index.php,否则会出现404,这与你是否配置默认主页与否无关,例如:http://www.domain.com/index.php/user/index/index
对于其它路由协议我推荐在application.ini中配置好,下面是我的配置文件:
;自定义路由;顺序很重要;index.php/list/test/abc--->index.php/index/index/index/name/test/value/abcroutes.regex.type="regex"routes.regex.match="#^list/([^/]*)/([^/]*)#"routes.regex.route.controller=Indexroutes.regex.route.action=actionroutes.regex.map.1=nameroutes.regex.map.2=value;index.php?m=m&c=c&a=a&test=555--->index.php/m/c/a/test/555routes.simple.type="simple"routes.simple.module=mroutes.simple.controller=croutes.simple.action=a;index.php?r=m/c/a&test=555--->index.php/m/c/a/test/555routes.supervar.type="supervar"routes.supervar.varname=r;默认的Yaf_Application;将会读取此节配置;补充路由定义;index.php/product/test/555--->index.php/index/product/info/name/test/value/555routes.rewrite.type="rewrite";routes.rewrite.match="/product/:name/:value"routes.rewrite.match="/product/:ident/*"routes.rewrite.route.module=userroutes.rewrite.route.controller=indexroutes.rewrite.route.action=index
这样我们就可以在Bootstrap.php中这样写了:
<?php class Bootstrap extends Yaf_Bootstrap_Abstract { public function _initConfig(Yaf_Dispatcher $dispatcher) { //配置文件添加 Yaf_Registry::set('config', Yaf_Application::app()->getConfig()); } //配置路由 public function _initRoute(Yaf_Dispatcher $dispatcher) { $router = Yaf_Dispatcher::getInstance()->getRouter(); $router->addConfig(Yaf_Registry::get("config")->routes); } }?>
Yaf_Route_Simple和Yaf_Route_Supervar的用法官网说得很清楚,这里也不再重复
重点谈一下Yaf_Route_Rewrite
这个路由协议的配置见上面ini中“补充路由定义”,routes.rewrite.type="rewrite"指出是该协议是哪个路由协议(Yaf_Route_Rewrite),routes.rewrite.match="/product/:ident/*"指出了uri的模式,routes.rewrite.route.module=user、routes.rewrite.route.controller=index、routes.rewrite.route.action=index分别指出了module,controller,action,所以请求的uri一旦符合对应的模式,就会访问..../modules/User/controllers/index.php/IndexAction
Yaf_Route_Regex同Yaf_Route_Rewrite
好了,时间不早了,大家如果还有什么疑问欢迎给我发私信或者发邮箱或者给我评论~
- yaf 路由协议配置测试
- Yaf 路由配置测试
- yaf -- 路由访问/配置
- yaf默认路由
- Yaf学习之路由
- 交换机路由协议配置
- mfloo 路由协议 场景测试
- yaf 框架路由解析过程
- 路由协议原理及配置
- OSPF路由协议的配置
- Yaf 2.1性能测试(Yaf 2.1 Benchmark)
- Yaf安装及配置
- yaf框架获取配置
- PhpStrom8.0.3配置Yaf
- 如何安装配置yaf
- yaf 框架配置访问
- 今天做路由实验学习体会---配置OSPF路由协议
- 实现一个手动配置路由表的无线路由协议
- Linux下用命令格式化U盘
- Java NIO系列教程(七) FileChannel
- SQLServer 复制和数据库镜像 详细配置部署
- CRF的库资源
- iOS: 剪裁UIImage部分不规则区域
- yaf 路由协议配置测试
- 黑马程序员————引用型变量的形式参数和返回值,权限修饰符,内部类
- [3]_人人都是产品经理
- php浮点数精确运算
- Android 开发中,如何将 SQLite 和 APK 一起打包发布
- Two Sum的快排暴力解法
- mysql 的count(*)统计结果很慢?为什么
- Android 数据库打包随APK发布
- 如何判断手机浏览器是否有安全隐患?