yaf框架流程三
路由的原理请看http://yaf.laruence.com/manual/yaf.routes.html这个链接
要点:路由的顺序是堆栈模式的,及最后添加的路由规则最优先。由上两篇可知,定义的第一条路由是application实例化时候的new Yaf_Route_Static()。
然后在bootstrap里有初始化路由的操作,主要方法是:
1.从配置添加
$routes = $this->config->routes;
$router = $dispatcher->getRouter();
$router->addConfig($routes);
2.语句添加
$route = new Yaf_Route_Rewrite(
"/product/list/:id/:name",
array(
"controller" => "product",
"action" => "info",
)
);
$router->addRoute('dummy', $route);
通过$dispatcher->getRouter()->getRoutes()可以查看到
array (size=)
'_default' =>
object(Yaf_Route_Static)[]
'index' =>
object(Yaf_Route_Regex)[]
protected '_route' => string '#^/([a-zA-Z]+)/?#' (length=)
protected '_default' =>
array (size=)
'module' => string 'Index' (length=)
'controller' => string 'Index' (length=)
'action' => string 'Index' (length=)
protected '_maps' =>
array (size=)
=> string 'name' (length=)
protected '_verify' =>
array (size=)
'module' => string 'Index' (length=)
'controller' => string 'Index' (length=)
'action' => string 'Index' (length=)
protected '_reverse' => null
'regex' =>
object(Yaf_Route_Regex)[]
protected '_route' => string '#^list/([^/]*)/([^/]*)#' (length=)
protected '_default' =>
array (size=)
'controller' => string 'Index' (length=)
'action' => string 'action' (length=)
protected '_maps' =>
array (size=)
=> string 'name' (length=)
=> string 'value' (length=)
protected '_verify' =>
array (size=)
'controller' => string 'Index' (length=)
'action' => string 'action' (length=)
protected '_reverse' => null
'simple' =>
object(Yaf_Route_Simple)[]
protected 'controller' => string 'c' (length=)
protected 'module' => string 'm' (length=)
protected 'action' => string 'a' (length=)
'supervar' =>
object(Yaf_Route_Supervar)[]
protected '_var_name' => string 'r' (length=)
'rewrite' =>
object(Yaf_Route_Rewrite)[]
protected '_route' => string '/product/:name/:value' (length=)
protected '_default' =>
array (size=)
'controller' => string 'product' (length=)
'action' => string 'info' (length=)
protected '_verify' =>
array (size=)
'controller' => string 'product' (length=)
'action' => string 'info' (length=)
protected '_reverse' => null
'dummy' =>
object(Yaf_Route_Rewrite)[]
protected '_route' => string '/product/list/:id/:name' (length=)
protected '_default' =>
array (size=)
'controller' => string 'product' (length=)
'action' => string 'info' (length=)
protected '_verify' => null
protected '_reverse' => null
可以看出保存为一个数组,顺序与配置的顺序一致,语句最后添加的也在最后。
yaf框架流程三的更多相关文章
- yaf框架流程二
这篇讲讲yaf的配置文件,首先上我的配置代码: [common] ;必选配置 ;application.directory String 应用的绝对目录路径 ;可选配置 ;名称 值类型 默认值 说明 ...
- yaf框架流程四
在前面的章节,在bootstrap里添加了一个benchmark插件,简单介绍下yaf的插件机制:http://yaf.laruence.com/manual/yaf.plugin.html Yaf定 ...
- Yaf框架下类的自动加载
前面两篇博客分别讲述了PHP自带的类加载和composer中类的自动加载,其实Yaf框架也实现了基于PSR0和PSR4的类的自动加载.根据我对Yaf下类的自动加载方式的理解写下这篇博客.由于接触Yaf ...
- yaf框架学习笔记
1.yaf框架支持简单的试图引擎,并且支持用户自定义视图引擎,比如smarty. 2.Yaf_Request_Http::getQuery ,Yaf_Request_Http::getQuery ( ...
- 从 0 开始手写一个 Mybatis 框架,三步搞定!
阅读本文大概需要 3 分钟. MyBatis框架的核心功能其实不难,无非就是动态代理和jdbc的操作,难的是写出来可扩展,高内聚,低耦合的规范的代码. 本文完成的Mybatis功能比较简单,代码还有许 ...
- php 安装yaf扩展和yaf框架
一.安装yaf扩展(windows安装) 1.查看你电脑安装的开发环境(phpinfo()的信息),查找 "Zend Extension Build"和"PHP Exte ...
- MVC系列——MVC源码学习:打造自己的MVC框架(三:自定义路由规则)
前言:上篇介绍了下自己的MVC框架前两个版本,经过两天的整理,版本三基本已经完成,今天还是发出来供大家参考和学习.虽然微软的Routing功能已经非常强大,完全没有必要再“重复造轮子”了,但博主还是觉 ...
- JavaScript框架设计(三) push兼容性和选择器上下文
JavaScript框架设计(三) push兼容性和选择器上下文 博主很久没有更博了. 在上一篇 JavaScript框架设计(二) 中实现了最基本的选择器,getId,getTag和getClass ...
- 【原创】NIO框架入门(三):iOS与MINA2、Netty4的跨平台UDP双向通信实战
前言 本文将演示一个iOS客户端程序,通过UDP协议与两个典型的NIO框架服务端,实现跨平台双向通信的完整Demo.服务端将分别用MINA2和Netty4进行实现,而通信时服务端你只需选其一就行了.同 ...
随机推荐
- HDU 1217 Arbitrage (Floyd)
Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...
- Win7系统配置IIS7服务
1.开启IIS7服务 打开控制面板,选择并进入“程序”,双击“打开或关闭Windows服务”,在弹出的窗口中选择“Internet信息服务”下面所有地选项,点击确定后,开始更新服务. 2.安装web文 ...
- (2)在vs2010上配置opengl
参考自http://www.yakergong.net/nehe/ 在Visual Studio 2003 中创建基于Nehe SDK的应用程序分为以下几个步骤: 创建一个空白的工程文件 包含Nehe ...
- Ubuntu安装取色软件
sudo apt-get install Gpick
- Hibernate的配置文件解析
配置mybatis.xml或hibernate.cfg.xml报错: <property name="connection.url">jdbc:mysql://loca ...
- activeMQ主要的几类集群部署方式
官方主从实现的文档:http://activemq.apache.org/masterslave.html 一.activeMQ主要的几类部署方式比较 1.默认的单机部署(kahadb) acti ...
- android AsyncTask异步下载并更新进度条
AsyncTask异步下载并更新进度条 //如果不是很明白请看上篇文章的异步下载 AsyncTask<String, Integer, String> 第一个参数:String 传入 ...
- PHP也20岁了
当今许多世界著名的编程语言的年纪已经够大了.举个例子,PHP昨天过了生日已经20岁了,Python也24岁,HTML已经服务了22年,Ruby和JavaScript有20年,Java前段时间刚过了20 ...
- 如何通过 jQuery text() 和 html()
text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元素的内容(包括 HTML 标记) val() - 设置或返回表单字段的值 $("#btn1").c ...
- 自动化测试之python安装
1.首先访问http://www.python.org/download/去下载最新的python版本. 2.安装下载包,一路next. 3.为计算机添加安装目录搭到环境变量,如图把python的安装 ...