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 4389 X mod f(x) 数位DP
思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...
- lintcode:整数排序||
题目 给一组整数,按照升序排序.使用归并排序,快速排序,堆排序或者任何其他 O(n log n) 的排序算法. 解题 归并排序 public class Solution { /** * @param ...
- 【PSR规范专题(5)】PSR-4 改进后的自动加载规范
本文转自: https://github.com/PizzaLiu/PHP-FIG/blob/master/PSR-4-autoloader-cn.md 关键词 "必须"(&quo ...
- 返回Json数据浏览器带上<pre></pre>标签解决方法
问题: 当后台获取到前台传来的文件时(例如上传功能, 导入功能), 返回类型为application/json, 这个时候响应到前端的JSON格式的数据格式可能是: <pre style=&q ...
- C++:文件的输入和输出
1.共同的打开文件方式: fin.open("test.txt",ios::binary) fout.open("test.txt",ios::binary) ...
- sublime3配置Quick-X+自动错误提示
sublime3配置 安装Package Control 配置Quick-x API提示 配置Lua自动语法错误提示 sublime3 安装 Package Control View->Show ...
- http 服务
今天把一个功能模块做成了http服务,这还是第一次写http服务,纪录下来. package com.chuntent.itemsearch; import java.io.BufferedReade ...
- notepad++使用技巧及插件汇总
NppAutoIndent 自动缩进CCompletion 自动补全.TextFX 插件nppFTP 运行程序 ============================================ ...
- C#基础(二)
变量的命名规则: 1.变量名由字母,数字 ,下划线组成.@ 中文 2.首字母,不能是数字 3.不能与关键字重名 变量的定义 语法: 数据类型 变量名[=值]; int a; //只定义变量 ...
- lcd ram/半反穿技术解析【转】
转自:http://bbs.meizu.cn/viewthread.php?tid=3058847&page=1 我的话题应该会比较长一些.但是大致板块如下:1.LCD RAM;-->此 ...