路由的原理请看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. POJ 1658

    #include<iostream>//cheng da cai zi using namespace std; int main() { int i; int time; ]; cin& ...

  2. iOS多线程的初步研究(二)-- 锁

    谈到线程同步,一般指如何对线程间共享数据的同步读写,如何避免混乱的读写结果.一个基本的解决办法就是使用锁(LOCK). iOS提供多种同步锁的类和方法,这里介绍下基本用法. 1. NSLock:最基本 ...

  3. Webpack教程二

    Webpack教程一 开发技巧 启用source-map 现在的代码是合并以后的代码,不利于排错和定位,只需要在config中添加 ... devtool: 'eval-source-map', .. ...

  4. 基于ant的jmeter自动化性能测试

    准备工作: 1.java的运行环境正常,及运行java -version.javac -version能正常输出java版本: 2.ant的运行环境正常,使用ant需要配置环境变量,编辑/etc/pr ...

  5. Spark基础与Java Api介绍

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3832405.html  一.Spark简介 1.什么是Spark 发源于AMPLab实验室的分布式内存计 ...

  6. java 语法错误 (操作符丢失) 在查询表达式

    遇到的详细问题: a[0]="11"; a[1]="2223"; a[2]="333"; sta.executeUpdate("i ...

  7. GDB下查看内存命令(x命令)

    http://blog.csdn.net/allenlinrui/article/details/5964046 可以使用examine命令(简写是x)来查看内存地址中的值.x命令的语法如下所示: x ...

  8. C#:MapControl基本操作代码整理

    整理了 MapConrol各基本功能的实现代码 using System; using System.Collections.Generic; using System.Linq; using Sys ...

  9. MSBuild和Jenkins搭建持续集成环境

    http://www.2cto.com/os/201409/334323.html http://my.oschina.net/anxuyong/blog/353897 http://www.cnbl ...

  10. Myeclipse 2014 javascript 添加 jquery 代码提示

    近日在写js,在myeclipse中没有jquery代码的提示着实不方便,在网上使用度娘搜索添加提示方式,试了多种,现经测试以下方式可取. 1.打开help菜单下的install from site. ...