手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:bind

创建Yii扩展

用yii进行开发的时候,不可避免的就会使用其他的插件,当然也需要自己来为他作扩展,所以,Yii的这一章就一定要看了(http://www.yiiframework.com/doc/guide/1.1/zh_cn/extension.create)。

官方介绍了这些:

  1. Application Component(应用部件)
  2. Behavior
  3. Widget(小工具)
  4. Action(动作)
  5. Filter(过滤器)
  6. Controller(控制器)
  7. Validator(验证)
  8. Console Command(控制台命令)
  9. Module(模块)
  10. Generic Component(通用组件)
可惜这此翻译还是有中有英。。没有完全翻译成中文,不过看看的话还是没问题的。。(behavior就没有翻译。。。)
有空,我会继续看下去。widget还正在看,功能正是我想要的。(博客上非常需要这一个玩意)

Tags: framework, yii, 开发笔记

dedecms:如何在runphp=yes的标签中使用其他field值

dedecms有强大的TAG自定义功能,但如果你是在runphp=yes的情况下,你无法使用[field]等标签,因为它不解释了(都当成PHP代码了,怎么可能解析呢?)
怎么办?
查了一下google,没有发现解决方法。所以我想了很久想出一个临时性的解决方法,即用全局变量来解决这个问题。。
{dede:php}$GLOBALS['xxoo']=$arc->Fields['fieldname']{/dede:php}
{dede:field.xxxx runphp="yes"}@me="test".@me."-test".$GLOBALS['xxoo'];{/dede:field.xxxx}
即,先开一个PHP的标签,把想赋的值替换给global变量。然后在另外的运行中将field值赋值给他。

写的乱,不过还是解决了这个问题了。。

Tags: dedecms, runphp, field

JianHua Zhang的Typecho阅读笔记一:页面渲染及路由机制

文章来自:http://blog.csdn.net/jh_zzz/archive/2010/01/11/5173806.aspx,由于我也正在看typecho这个玩意所以,就记录下来。虽然我一天下来,也看了不少代码,但毕竟没有深读过。对于流程啥的,还没有开始关心,只是为了写而写。

第一篇:页面渲染及路由机制

index.php 开始看,

 

/** 初始化组件 */

Typecho_Widget:: widget('Widget_Init' );

 

Typecho_Widget:: widget 函数,查找 Widget\Init.php Widget 下的文件都是从 Typecho_Widget 派生的,这里创建该对象实例,并将相关的 Request Response 对象作为参数传递过去,然后调用该对象的 execute 方法。

 

看一下 Init 中的 execute ,首先会初始化一些参数,重点看看 MVC 架构的路由:

Typecho_Router:: setPathInfo($this -> request-> getPathInfo());

Typecho_Router:: setRoutes($options -> routingTable);

首先设置路径,然后初始化路由, $options -> routingTable 默认值是在安装时写在数据库中的,运行时再读出来, Typecho_Router setRoutes 函数调用了 Typecho_Router_Parser parse 函数, parse 函数遍历整个 routingTable 数组,将处理后的路由数组返回给 Typecho_Router ,保存在 $_routingTable

PHP代码
  1. if  (! $validated  &&  ! emptyempty ($this -> _archiveSlug)) {  
  2.     $themeFile = $this -> _archiveType . '/' . $this -> _archiveSlug . '.php' ;  
  3.     if (file_exists($themeDir . $themeFile )) {  
  4.         $this -> _themeFile = $themeFile ;  
  5.         $validated = true ;  
  6.     }  
  7. }   

 

这里需要看一下 _archiveType _archiveSlug 是怎么来的:

Widget_Archived execute 函数中会根据 $this -> parameter-> type 执行相应的 handler

PHP代码
  1. if  (isset ($handles [$this -> parameter-> type])) {  
  2.     $handle = $handles [$this -> parameter-> type];  
  3.     $this -> {$handle }($select , $hasPushed );  
  4. else {  
  5.     $hasPushed = $this -> pluginHandle()-> handle($this -> parameter-> type, $this , $select );  
  6. }   

 

$this -> parameter-> type 这个变量是在构造函数中赋值的 :

$this -> parameter-> type = Typecho_Router:: $current ;

Typecho_Router:: $current 根据路由表可以查到对应于 index.php 就是 index

 

所以对于上面标黄的代码对应于 index.php 最终执行的是的是 $handles [‘index’] 对应的 handle ,就是 indexHandle 。可以看到对于其他的 Handle 一般都会设置 _archiveType _archiveSlug 变量, indexHandle 没有,因为 _archiveType 默认就是 index ,所以在 index.php _archiveType 等于 index _archiveSlug 为空。

 

所以根据前面 render 函数中的代码,最终是找到对应于 $themeDir 下的 $this -> _archiveType . '/' . $this -> _archiveSlug . '.php' 文件,然后直接包含进来,我们看到的就是这个文件的输出了。

 

/** 注册一个结束插件 */

Typecho_Plugin:: factory('index.php' )-> end();

Tags: typecho, 笔记