好!欢迎访问迷津渡口 现在时间是: 天气 °C ~ °C

迷津渡口

越感到迷惑 越接近真理

emlog MVC解构5--Dispatcher和路由表分析

注意:前台MVC结构功能主要是向服务器请求数据,只有评论是提交数据。


Dispatcher:路由分发器,可谓是emlog MVC结构的关键。

所谓路由,就是确定到达目的的最佳路径和通过网络传输信息。


在emlog里面,路由分发器的作用与路由类似:

路由分发器获取到目的路径,通过正则表达式等判断,获得需要调用的Controller、方法及参数。

Controller获取数据后把数据发送给相应的模型,模型处理好相应的数据后有存储到数据库里面或者更新缓存和变量,最后Controller将信息传递给View,进行输出。


下面详细解析Dispatcher类:

属性列表:

属性注释
static $_instance静态属性,保存一个实例化的Dispatcher对象
private $_model目标请求模块,保存Controller的类名
private $_method目标请求模块方法,保存Controller调用的方法名
private $_params目标请求参数,保存正则表达式获取的路径和路径分量构成的一个数组
private $_routingTable路由表,保存通过Options::getRoutingTable()的静态方法返回的路由表,为二阶数组
private $_path访问路径,函数处理后不包含 BLOG_URL和index.php的路径

方法列表:

方法注释
private function __construct()
构造方法,调用setPath()方法配置$_path,获取$_routingTable,迭代分析路由表数据,利用正则表达式判断配置$_model,$_method,$_params
public static function getInstance()静态方法,实例化静态属性$_instance并返回
public function dispatch()实例化$_model对象,并调用$_method方法,参数为$_params
public static function setPath()静态方法,返回去除干扰项的路径$path


下面分析一下所谓的路由表:

$routingtable = array(
    array(
	'model' => '模型的名称',
	'method' => '调用的方法',
	'reg_0' => '正则表达式',
	'reg_1' => '正则表达式',
	...
    ),
    ...
);

容易发现除了calendar,所有的model都是Controller,在类文件include/controller路径下。

calendar是一个工具类,在include/lib下面,你可以通过

BLOG_URL.'?action=cal'

获得一个个性化的日历。例如http://www.qingzz.cn/?action=calhttp://www.qingzz.cn/index.php?action=cal


method就是将要调用的方法,reg_*就是正则表达式啦,和isurlrewrite参数有关,但reg_0是默认的路径,如果路径无法匹配'reg_'.Option::get('isurlrewrite')所对应的表达式,但能匹配reg_0所对应的表达式则依旧可行,前者优先匹配。

正则表达式具体如何匹配就不分析了,自己看。


提供简单方法查看处理后的路径调用的是哪个Controller,方法和参数,修改dispatch()方法为:

public function dispatch(){
    $module = new $this->_model();
    $method = $this->_method;
    print '$_path:'.$this->_path."<br>".
          '$_model: '.$this->_model."<br>".
          '$_method: '.$this->_method."<br>".
          '$_params: ';
    print_r($this->_params);
    $module->$method($this->_params);
}

可以通过改变访问路径不断验证理解的正则表达式是否正确啦~

点赞1
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
milligande
 milligande 2018-12-15 22:54回复
#14
<a href="http://www.femmedeguinee.com/nike-flyknit-white-men-skot">nike flyknit white men</a> <a href="http://www.hollerrealtor.com/billig-nike-hyperdunk-2014-low-dam%C3%A4nner-lila-sneakere">billig nike hyperdunk 2014 low dam盲nner lila</a> <a href="http://www.psychedelicsf.com/air-jordan-1-foamposite-paranorman-x-runninga">air jordan 1 foamposite paranorman x</a> <a href="http://www.kristyhuston.com/mackage-coat-with-black-fur-mackager">mackage coat with black fur</a> <a href="http://www.minruteguide.com/nike-cortez-oatmeal-runninga">nike cortez oatmeal</a> <a href="http://www.dennygorman.com/prada-brown-loafers-pradar">prada brown loafers</a>
[url=http://www.milligande.com/]milligande[/url]
moldedeps
 moldedeps 2018-12-14 16:08回复
#13
<a href="http://www.rivacover.com/air-jordan-true-flight-pink-quilt-sportsc">air jordan true flight pink quilt</a> <a href="http://www.slimtobody.com/bon-march%C3%A9-asics-gel-sendai-2-femmes-bleu-trainersd">bon march茅 asics gel sendai 2 femmes bleu</a> <a href="http://www.mgnmilitaria.com/texas-rangers-gray-hat-linux-hata">texas rangers gray hat linux</a> <a href="http://www.rahwindsor.com/nike-air-max-zero-white-on-feet-runninga">nike air max zero white on feet</a> <a href="http://www.ceethebarber.com/michael-kors-brown-and-pink-purse-mkr">michael kors brown and pink purse</a> <a href="http://www.saatchixblog.com/hombres-nike-air-max-95-rojo-shoesn">hombres nike air max 95 rojo</a>
governisation
 governisation 2018-12-11 18:35回复
#12
<a href="http://www.cakirgozoto.com/silver-pink-womens-nike-kaishi-shoes-foota">silver pink womens nike kaishi shoes</a> <a href="http://www.burayagidin.com/new-era-blank-camo-fitted-hats-lines-hatd">new era blank camo fitted hats lines</a> <a href="http://www.ftpronto.com/nike-free-ebay-kleinanzeigen-trainersb">nike free ebay kleinanzeigen</a> <a href="http://www.bukafalar.com/%EF%BB%BFconverse-shoes-shoesz">锘縞onverse shoes</a> <a href="http://www.essodustade.com/femminile-puma-future-cat-bianca-shoesn">femminile puma future cat bianca</a> <a href="http://www.biyotestatik.com/nobis-cartel-jacket-review-nobisr">nobis cartel jacket review</a>
ksmartcity
 ksmartcity 2018-12-04 11:01回复
#11
<a href="http://www.meghanfresta.com/parajumper-mens-sale-parajumpersr">parajumper mens sale</a> <a href="http://www.coldwaterapps.com/nike-lunar-vapor-trout-spectrum-mens-baseball-cleat-trainersg">nike lunar vapor trout spectrum mens baseball cleat</a> <a href="http://www.drmilliecalko.com/nike-roshe-flyknit-womens-gold-sneakera">nike roshe flyknit womens gold</a> <a href="http://www.ovisausa.com/vibram-fivefingers-jaya-orange-purple-sportsa">vibram fivefingers jaya orange purple</a> <a href="http://www.lumalenders.com/bon-march%C3%A9-new-balance-360-femmes-sneakerf">bon march茅 new balance 360 femmes</a> <a href="http://www.eysenreich.com/adidas-ultra-boost-herre-bl%C3%A5-sneakera">adidas ultra boost herre bl氓</a>
ksmartcity http://www.ksmartcity.com/
minsonphoto
 minsonphoto 2018-11-30 23:58回复
#10
<a href="http://www.amyhessatx.com/michael-michael-kors-wallet-mkr">michael michael kors wallet</a> <a href="http://www.sleepysdirect.com/burberry-scarf-mens-outlet-scarfr">burberry scarf mens outlet</a> <a href="http://www.postanje.com/2012-team-usa-olympics-navy-blue-short-nflv">2012 team usa olympics navy blue short</a> <a href="http://www.geoffglisson.com/nike-air-max-1-v-sp-leather-sneakers-sportsf">nike air max 1 v sp leather sneakers</a> <a href="http://www.mobilsevgili.com/nike-air-max-neon-zalando-sportsd">nike air max neon zalando</a> <a href="http://www.amarthur.com/nike-air-max-terra-180-herren-wei%C3%9F-sneakerd">nike air max terra 180 herren wei脽</a>
minsonphoto http://www.minsonphoto.com/
damimiyy
 damimiyy 2018-11-24 03:49回复
#9
<a href="http://www.alikexue.com/under-armour-curry-2-hommes-trainersb">under armour curry 2 hommes</a> <a href="http://www.evorewards.com/nike-air-max-hybrid-boots-sneakerd">nike air max hybrid boots</a> <a href="http://www.betroopsports.com/adidas-springblade-ignite-hombres-amarillo-runningd">adidas springblade ignite hombres amarillo</a> <a href="http://www.malagakizomba.com/nike-lebron-witness-dam%C3%A4nner-gr%C3%BCn-sneakerb">nike lebron witness dam盲nner gr眉n</a> <a href="http://www.maxpectations.com/purple-red-womens-nike-archive-83-shoes-trainersa">purple red womens nike archive 83 shoes</a> <a href="http://www.katiagrinkov.com/nike-huarache-dress-silver-shoesa">nike huarache dress silver</a>
damimiyy http://www.damimiyy.com/
torilsdesign
 torilsdesign 2018-11-24 03:25回复
#8
<a href="http://www.cocoadancer.com/air-huarache-gray-or-grey-runningd">air huarache gray or grey</a> <a href="http://www.noteablepost.com/nike-free-run-2-dam%C3%A4nner-schwarz-trainerse">nike free run 2 dam盲nner schwarz</a> <a href="http://www.kidbleach.com/nike-flyknit-air-max-mens-black-nike-skof">nike flyknit air max mens black nike</a> <a href="http://www.gregnovak.com/ray-ban-tech-carbon-fibre-sunglasses-usa-sunglassesb">ray ban tech carbon fibre sunglasses usa</a> <a href="http://www.dxmvrc.com/nike-kd-4-skot">nike kd 4</a> <a href="http://www.ladivorcecpa.com/%EF%BB%BFhombres-nike-air-max-270-blanco-shoesn">锘縣ombres nike air max 270 blanco</a>
torilsdesign http://www.torilsdesign.com/
gollevo
 gollevo 2018-11-22 00:30回复
#7
<a href="http://www.myvetsbest.com/ray-ban-sunglasses-for-men-polarized-black-sunglassesc">ray ban sunglasses for men polarized black</a> <a href="http://www.manskapsboden.com/cheap-parajumper-coats-parajumpersr">cheap parajumper coats</a> <a href="http://www.ericaamadori.com/fendi-leather-messenger-bag-fendir">fendi leather messenger bag</a> <a href="http://www.heppemobil.com/alexander-scott-54-jersey-nhl-nfld">alexander scott 54 jersey nhl</a> <a href="http://www.blickpoy.com/bon-march%C3%A9-air-jordan-horizon-femmes-blanc-runningb">bon march茅 air jordan horizon femmes blanc</a> <a href="http://www.purchasemenu.com/ugg-boots-classic-tall-chestnut-size-8-uggsr">ugg boots classic tall chestnut size 8</a>
motirealtor
 motirealtor 2018-11-19 04:09回复
#6
<a href="http://www.uilstrategie.com/bon-march%C3%A9-nike-kobe-9-mid-femmes-jaune-trainerse">bon march茅 nike kobe 9 mid femmes jaune</a> <a href="http://www.apocreative.com/black-blue-mens-adidas-samba-primeknit-shoes-shoesb">black blue mens adidas samba primeknit shoes</a> <a href="http://www.easytanklevel.com/ray-ban-cats-5000-pink-sunglassesr">ray ban cats 5000 pink</a> <a href="http://www.mesassy.com/nike-free-run-3-fluo-skof">nike free run 3 fluo</a> <a href="http://www.eventyrshop.com/nike-free-flyknit-sz-10-footc">nike free flyknit sz 10</a> <a href="http://www.foremostgold.com/adidas-tubular-x-all-white-skot">adidas tubular x all white</a>
amyhessatx
 amyhessatx 2018-11-16 12:55回复
#5
<a href="http://www.rivacover.com/adidas-superstar-very-cheap-shoesf">adidas superstar very cheap</a> <a href="http://www.slimtobody.com/mens-nike-air-max-98-green-spain-shoeso">mens nike air max 98 green spain</a> <a href="http://www.mgnmilitaria.com/pandora-safety-chain-canada-pandorar">pandora safety chain canada</a> <a href="http://www.rahwindsor.com/adidas-zx-flux-schwarz-and-rose-gold-dam%C3%A4nner-glasses-shoesv">adidas zx flux schwarz and rose gold dam盲nner glasses</a> <a href="http://www.ceethebarber.com/buy-parajumpers-online-parajumpersr">buy parajumpers online</a> <a href="http://www.saatchixblog.com/mackage-long-wool-coat-mackager">mackage long wool coat</a>
amyhessatx http://www.amyhessatx.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸