路由的原理请看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框架流程三的更多相关文章

  1. yaf框架流程二

    这篇讲讲yaf的配置文件,首先上我的配置代码: [common] ;必选配置 ;application.directory String 应用的绝对目录路径 ;可选配置 ;名称 值类型 默认值 说明 ...

  2. yaf框架流程四

    在前面的章节,在bootstrap里添加了一个benchmark插件,简单介绍下yaf的插件机制:http://yaf.laruence.com/manual/yaf.plugin.html Yaf定 ...

  3. Yaf框架下类的自动加载

    前面两篇博客分别讲述了PHP自带的类加载和composer中类的自动加载,其实Yaf框架也实现了基于PSR0和PSR4的类的自动加载.根据我对Yaf下类的自动加载方式的理解写下这篇博客.由于接触Yaf ...

  4. yaf框架学习笔记

    1.yaf框架支持简单的试图引擎,并且支持用户自定义视图引擎,比如smarty. 2.Yaf_Request_Http::getQuery  ,Yaf_Request_Http::getQuery ( ...

  5. 从 0 开始手写一个 Mybatis 框架,三步搞定!

    阅读本文大概需要 3 分钟. MyBatis框架的核心功能其实不难,无非就是动态代理和jdbc的操作,难的是写出来可扩展,高内聚,低耦合的规范的代码. 本文完成的Mybatis功能比较简单,代码还有许 ...

  6. php 安装yaf扩展和yaf框架

    一.安装yaf扩展(windows安装) 1.查看你电脑安装的开发环境(phpinfo()的信息),查找 "Zend Extension Build"和"PHP Exte ...

  7. MVC系列——MVC源码学习:打造自己的MVC框架(三:自定义路由规则)

    前言:上篇介绍了下自己的MVC框架前两个版本,经过两天的整理,版本三基本已经完成,今天还是发出来供大家参考和学习.虽然微软的Routing功能已经非常强大,完全没有必要再“重复造轮子”了,但博主还是觉 ...

  8. JavaScript框架设计(三) push兼容性和选择器上下文

    JavaScript框架设计(三) push兼容性和选择器上下文 博主很久没有更博了. 在上一篇 JavaScript框架设计(二) 中实现了最基本的选择器,getId,getTag和getClass ...

  9. 【原创】NIO框架入门(三):iOS与MINA2、Netty4的跨平台UDP双向通信实战

    前言 本文将演示一个iOS客户端程序,通过UDP协议与两个典型的NIO框架服务端,实现跨平台双向通信的完整Demo.服务端将分别用MINA2和Netty4进行实现,而通信时服务端你只需选其一就行了.同 ...

随机推荐

  1. java 如何从配置文件(.properties)中读取内容

    1.如何创建.properties文件 很简单,建立一个txt文件,并把后缀改成.properties即可 2.将.properties文件拷入src的根目录下 3..properties文件内容格式 ...

  2. VMware 进入bios

    在虚拟机创建目录中找到.vmx结尾的文件. 添加bios.forceSetupOnce = "TRUE". 打开虚拟机,他会自动进入bios,随后他会把bios.forceSetu ...

  3. zoj 2686 Cycle Game 博弈论

    其实规律很好找的,当从某点开始,向某一边找出非0的个数,为奇数时必胜. 代码如下: #include<iostream> #include<cstdio> using name ...

  4. 关于playmaker play animation出现警告 The AnimationClip 'xxx' used by the Animati ...

    转载自网络: 出现这个提示: The AnimationClip 'xxx' used by the Animation component 'xxx' must be marked as Legac ...

  5. lintcode:两个数组的交

    题目 返回两个数组的交 样例 nums1 = [1, 2, 2, 1], nums2 = [2, 2], 返回 [2]. 解题 排序后,两指针找相等元素,注意要去除相同的元素 public class ...

  6. C. Tourist's Notes

    题目链接 题意:n天内登山,相邻两次登山的高度差的绝对值小于等于1,也就是说每次高度变化只能是:0,1,-1.我们已经知道n天中部分天数人所在的山的高度,求最大的登山高度. 输入: n m  n 是天 ...

  7. QString::toWCharArray可以拷贝到宽字符串里

    wchar_t * sourcepath=new wchar_t[MAX_PATH];int s1=str.toWCharArray(sourcepath); sourcepath[s1]=0;

  8. IOS 的loadView 及使用loadView中初始化View注意的问题。(死循环并不可怕)

    在XCode 4.2后,我基本上的应用都不使用Xib文件了,虽然xib文件有很多好趣,可以快速免代码构建视窗,可以减少好多代码构建带来的麻烦,其实能用xib还是不错的,主要是我的机器打开xib来编辑时 ...

  9. C++:构造函数的默认参数知识拓展

    和普通函数一样,构造函数中参数的值既可以通过实参传递,也可以指定为某些默认值,即如果用户不指定实参值,编译系统就使形参取默认值.   例9.3的问题也可以使用包含默认参数的构造函数来处理.   [例9 ...

  10. Data Flow ->> Multicast

    Multicast的中文意思是组播或者多播.那自然这个组件干的事情就是可以把一份数据库输入给多少接收组件作为输入.这里有篇别人的博文讲到了Multicast的主要作用和应用场景:http://www. ...