用yii进行开发的时候,不可避免的就会使用其他的插件,当然也需要自己来为他作扩展,所以,Yii的这一章就一定要看了(http://www.yiiframework.com/doc/guide/1.1/zh_cn/extension.create)。
官方介绍了这些:
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值赋值给他。
写的乱,不过还是解决了这个问题了。。
文章来自: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代码
- if (! $validated && ! emptyempty ($this -> _archiveSlug)) {
- $themeFile = $this -> _archiveType . '/' . $this -> _archiveSlug . '.php' ;
- if (file_exists($themeDir . $themeFile )) {
- $this -> _themeFile = $themeFile ;
- $validated = true ;
- }
- }
这里需要看一下 _archiveType 和 _archiveSlug 是怎么来的:
在 Widget_Archived 的 execute 函数中会根据 $this -> parameter-> type 执行相应的 handler 。
PHP代码
- if (isset ($handles [$this -> parameter-> type])) {
- $handle = $handles [$this -> parameter-> type];
- $this -> {$handle }($select , $hasPushed );
- } else {
- $hasPushed = $this -> pluginHandle()-> handle($this -> parameter-> type, $this , $select );
- }
$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();