<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title>朝闻道的“爱学”日志</title>
		<link>http://www.ax.net.cn/</link>
		<description>天道酬勤，唯爱学可成才</description>
		<copyright>Copyright (C) 2004 Security Angel Team [S4T] All Rights Reserved.</copyright>
		<generator>SaBlog-X Version 1.6 Build 20080806</generator>
		<lastBuildDate>Fri, 10 Sep 2010 12:04:19 +0000</lastBuildDate>
		<ttl>30</ttl>
		<item>
			<guid>http://www.ax.net.cn/?action=show&amp;id=366</guid>
			<title>自动生成Thinkphp2.0能用的model名称驼峰命名规范</title>
			<author>admin</author>
			<description><![CDATA[<div class="codeText">
<div class="codeHead">PHP代码</div>
<ol start="1" class="dp-c">
    <li class="alt"><span><span>preg_replace(</span><span class="keyword">array</span><span>(</span><span class="string">&quot;/^([a-z])/e&quot;</span><span>,</span><span class="string">&quot;/_([a-z])/e&quot;</span><span>),&nbsp;</span><span class="keyword">array</span><span>(</span><span class="string">&quot;strtoupper('\\1')&quot;</span><span>,</span><span class="string">&quot;strtoupper('\\1')&quot;</span><span>),&nbsp;</span><span class="vars">$name</span><span>);&nbsp;&nbsp;</span></span></li>
</ol>
</div>
<p>效果将 user_ext 转换成 UserExt</p><br /><br /><a href="http://www.ax.net.cn/?action=show&amp;id=366" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.ax.net.cn/?action=show&amp;id=366</link>
			<category domain="http://www.ax.net.cn/?cid=13">thinkphp</category>
			<pubDate>2010-01-03 15:59</pubDate>
		</item>
		<item>
			<guid>http://www.ax.net.cn/?action=show&amp;id=287</guid>
			<title>thinkphp1.6的大体执行流程 方便定制模式扩展</title>
			<author>admin</author>
			<description><![CDATA[tp1.6的大体执行流程 方便定制模式扩展
index.php文件是入口文件 用户的所有操作由此文件接手

一 核心流程

1. 在入口文件index.php中先定义了thinkphp基类库所在路径和app应用库所在路径

2. require 基类库下的thinkphp.php文件

3. thinkphp.php文件先检测php版本是否低于5.0，如果低于5.0直接die退出

4. 检测是否已经生成核心执行文件~runtime.php 如果已经生成则require该~runtime.php 否则的话执行5-8流程（我觉得可以依靠检测NO_CACHE_RUNTIME是否被定义来决定是否使用~runtime.php，否则调用is_file会进行磁盘检测，而且这个操作非常频繁）

5. 如果尚未生成~runtime.php则require common/defines.php(系统定义文件)和common/paths.php(路径配置文件) 

6. 创建一个数组 数组中保存了一些文件路径 这些文件将被合在一起去掉空格成为~runtime.php，称之为编译列表吧 编译列表包括：
(1) common/function.php(公共函数文件)
(2) common/compat.php(php版本兼容文件,php版本低于5.2时被加入编译列表中，该文件中有若干php5.2以下版本不支持的函数)
(3) lib/think/core/base.class.php(thinkphp所有类从该抽象类继承，设置了自动变量)
(4) 项目目录/conf/core.php文件指定的核心文件列表(如果存在的话) 或 TP系统目录/common/core.php文件中指定的核心文件列表(前者不存在的话)，默认的核心文件列表中包含think/core/action.class.php,app.class.php,log.cass.php,model.class.php,view.class.php等核心文件

7. foreach编译文件列表并依次require(确保在没有~runtime.php的首次访问tp时候appclass一样可以正常工作)

8. 检查RUMTIME_PATH目录(默认为项目目录/Temp)是否存在，如不存在则创建项目目录列表（项目目录列表在paths.php文件中定义）

9. 如果没有定义NO_CACHE_RUNTIME该常量，则生成~runtime.php，也就是说可以在index.php入口文件定义NO_CACHE_RUNTIME使thinkphp每次运行都会执行5-8流程

~runtime.php由以下文件列表构成:
"ThinkPHP/Common/defines.php"(必须)
"ThinkPHP/Common/paths.php"(可定义常量PATH_DEFINE_FILE来配置)
"ThinkPHP/Common/functions.php"(必须)
"ThinkPHP/Common/compat.php"(仅在PHP版本低于5.2.0时)
"ThinkPHP/Lib/Think/Core/Base.class.php"(必须)
"ThinkPHP/Lib/Think/Exception/ThinkException.class.php"(core)
"ThinkPHP/Lib/Think/Core/Log.class.php"(core)
"ThinkPHP/Lib/Think/Core/App.class.php"(core)
"ThinkPHP/Lib/Think/Core/Action.class.php"(core)
"ThinkPHP/Lib/Think/Core/Model.class.php"(core)
"ThinkPHP/Lib/Think/Core/View.class.php"(core)
"ThinkPHP/Common/alias.php"(core)

括号中标识为core的文件，是由core.php来配置的，core.php文件的选择顺序为：
1 项目目录/conf/core.php
2 Thinkphp系统目录/Mode/THINK_MODE.php(仅在常量THINK_MODE被定义时)
3 Thinkphp系统目录/common/core.php


二 用户流程

index.php入口文件已经执行完require(THINK_PATH.'/ThinkPHP.php');了
接下来是$App = new app();  $App->run();

thinkphp.php有两种执行方式，那就是直接require ~runtime.php和no_cache_runtime方式，不管哪种方式，都会require base.class.php和app.class.php，那么就可以理解 $App=new app();是实例化的哪个文件中的App类：TP系统目录/Lib/Think/Core/App.class.php

App这个类从base类继承，是thinkphp这个mvc框架中非常关键的一个类。

在1.6版我拿到的代码中，App类有10个方法：

1. init()  初始化 主要工作是：加载配置文件 加载用户自定义php文件 
2. build() 编译项目
3. getModel() 获得实际模块名称
4. getAction() 获得实际操作名称
5. checkLanguage() 检查浏览器支持语言 在init()中被调用
6. checkTemplate() 检查模板，如不存在使用默认模板 在init()中被调用
7. exec() 执行应用实例 被run()调用
8. run() 运行应用实例
9. appException($e) 自定义异常处理 接手php异常
10.appError($e) 自定义错误处理 接手php错误


在index.php入口文件中，首先实例化了一个app类的对象，然后调用该对象的run方法，实质上就是调用了init()和run()这两个方法，那么我就来分析这两个方法的执行流程吧。

init()主要执行流程:
1. 使用app类的appError和appException来接手Php的异常和错误处理，appError和appExcetipion中通过lib/think/core目录下的logclass该方法记录了错误和异常，并且使用halt输出了一场，异常的输出和记录都是可以在配置文件中配置的。

2. 判断缓存文件~app.php是否存在，如果存在则include该文件，否则执行build方法
build方法将以下几个文件合并之后成为~app.php
1) 项目目录/common/common.php(如果存在)
2) 项目目录/conf/app.php(如果存在的话,合并此文件return的array包含的文件)
3) 项目目录/conf/conf.php中EXTEND_CONFIG_LIST数组设置的扩展配置文件列表
4) Thinkphp系统目录/common/convention.php 与 项目目录/conf/config.php两个配置文件合并后的配置(合并时config.php覆盖convention.php重复项)

3. 如果配置文件SESSION_AUTO_START为true则执行session_start()初始化session。

4. 如果配置文件中DISPATCH_ON为true则执行Dispatcher类的静态方法dispatch()，该方法将会使pathinfo等模式的路径解析出Module和Action放入$_GET数组中

5. 调用getModule和getAction两个方法分别获取模块名称和操作名称，然后赋予常量MODULE_NAME和ACTION_NAME

6. 加载(项目目录/conf/当前模块名称_config.php)该配置文件

7. 语言检查与模板检查


run()主要执行流程:

1. 记录应用初始化时间

2. 执行exec()

3. 记录结束时间

4. 保存日志


exec()主要执行流程:

1. 根据MODULE_NAME调用A()方法实例化一个控制器对象。

2. 调用控制器对象的名为ACTION_NAME的方法



==============================

匆匆结束，提醒大家一下 thinkphp中的module对应的是action.class.php而action是指的action.class的方法，而model封装的是数据库常用操作。<br /><br /><a href="http://www.ax.net.cn/?action=show&amp;id=287" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.ax.net.cn/?action=show&amp;id=287</link>
			<category domain="http://www.ax.net.cn/?cid=13">thinkphp</category>
			<pubDate>2009-06-18 15:33</pubDate>
		</item>
		<item>
			<guid>http://www.ax.net.cn/?action=show&amp;id=285</guid>
			<title>1.6版本TP的yhustc项目管理器的一些改善</title>
			<author>admin</author>
			<description><![CDATA[改善 原来项目路径不支持带下划线的目录，如：e:\www_root\b_com\b2c\index.php修正 原来模板总是引入了cx标签，现在svn上的1.6的默认加载1.6的标签，会出错啦。


附件我是我改好的，方便新手。
http://bbs.thinkphp.cn/attachment.php?aid=1127&k=676cb716a88dd6a7173f400f5efa305d&t=1245226057&sid=cb38KcRXaps7%2FU89UPtvaetbM5QoDSxV0%2BmUkOdHiHCy3xQ<br /><br /><a href="http://www.ax.net.cn/?action=show&amp;id=285" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.ax.net.cn/?action=show&amp;id=285</link>
			<category domain="http://www.ax.net.cn/?cid=13">thinkphp</category>
			<pubDate>2009-06-17 16:11</pubDate>
		</item>
		<item>
			<guid>http://www.ax.net.cn/?action=show&amp;id=284</guid>
			<title>thinkphp1.5移植到1.6的一些说明</title>
			<author>admin</author>
			<description><![CDATA[<p>1，1.5的版本可以多种URL结构共存，类似/Index/index和?m=Index&amp;a=index这种方式可以共存的，但是1.6就不行了，只能使用一种（我使用的是/Index/index）这样，如果是这里出现问题，表现出来的现象是代码接受不到$_POST过来的值，我这里表现出来的现象是验证码始终不正确（当然，因为PHP代码根本就没收到值&hellip;&hellip;）<br />
<br />
2，当然，就是别忘了修改index.php。<br />
<br />
3，对于数据的查询，只支持连贯操作了，也就是说$Dao-&gt;find($id)在1.6版本里面就不能用来，而应该改成$Dao-&gt;where(&quot;id=&quot;.$id)-&gt;find();虽然有点繁琐，但却是更规范了。</p>
<p><span class="Apple-style-span" style="word-spacing: 0px; font: medium 'Times New Roman'; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(68,68,68); line-height: 22px; font-family: Verdana, Helvetica, Arial, sans-serif; border-collapse: collapse; text-align: left">如果主键是id并且自动递增，可以直接用find()来查找，或者如果给find()传递一个数组，也可以使用<br style="line-height: normal; word-wrap: break-word" />
<br style="line-height: normal; word-wrap: break-word" />
getBy并没有取消，只不过需要注意到是1.5版本getById是查找主键，而1.6的getById是查找&quot;id&quot;字段了，不自动判断主键了</span></span><br />
<br />
4，layout和display合并了，如果想用layout，那么<br />
$this-&gt;display(&quot;Layout:xxx&quot;);其中xxx是你的层名称，这样&lt;layout&gt;标签也同样可以用，跟以前没什么区别。<br />
<br />
5,以前Action里的那些isPost,isGet之类的都取消了，大家可以自己根据1.5版本里的自己扩展，如果需要用到的话。<br />
<br />
6，url()取消了，取而代之的是U()<br />
<br />
7,动态操作，例如topN,getBy,deleteBy这些都取消了，请用关联操作<br />
<br />
8,如果Model里仅仅extends Model是只能做基本的增删改查到，如果想有自动验证和自动填充，那么需要这么写</p>
<div class="codeText">
<div class="codeHead">PHP代码</div>
<ol class="dp-c">
    <li class="alt"><span><span>import(</span><span class="string">&quot;Think.Core.Model.AdvModel&quot;</span><span>); &nbsp;&nbsp;</span></span></li>
    <li class=""><span class="keyword">class</span><span>&nbsp;XXXModel&nbsp;</span><span class="keyword">extends</span><span>&nbsp;AdvModel&nbsp;&nbsp;</span></li>
</ol>
</div>
<p><span class="Apple-style-span" style="word-spacing: 0px; font: medium 'Times New Roman'; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(68,68,68); line-height: 22px; font-family: Verdana, Helvetica, Arial, sans-serif; border-collapse: collapse; text-align: left">import(&quot;Think.Core.Model.AdvModel&quot;);也可以直接用import(&quot;AdvMode&quot;);</span></span></p>
<p><span class="Apple-style-span" style="word-spacing: 0px; font: medium 'Times New Roman'; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(68,68,68); line-height: 22px; font-family: Verdana, Helvetica, Arial, sans-serif; border-collapse: collapse; text-align: left"><span class="Apple-style-span" style="word-spacing: 0px; font: medium 'Times New Roman'; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(68,68,68); line-height: 22px; font-family: Verdana, Helvetica, Arial, sans-serif; border-collapse: collapse; text-align: left">要使用image类库的验证码，注意ORG/Util/Image.class.php 的213行<br style="line-height: normal; word-wrap: break-word" />
$randval = build_verify($length,$mode);<br style="line-height: normal; word-wrap: break-word" />
但function.php中已删去了这个build_verify()函数与及相关函数rand_string()，要使用该类的话，还是自己加上吧<br style="line-height: normal; word-wrap: break-word" />
觉得加在Image类中比较实在些。只是不知道符不符合规范<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">--------------------------<br style="line-height: normal; word-wrap: break-word" />
</font>Action类的$this-&gt;redirect()方法，不再是$this-&gt;redirect('操作'，'模块');<br style="line-height: normal; word-wrap: break-word" />
而是$this-&gt;redirect('模块/操作');<br style="line-height: normal; word-wrap: break-word" />
具体使用请参考U函数用法。<br style="line-height: normal; word-wrap: break-word" />
如此一来，跨项目跳转也很爽了。<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">------------------------</font><br style="line-height: normal; word-wrap: break-word" />
addAll,deleteAll,topN这些方法已删除<br style="line-height: normal; word-wrap: break-word" />
要实现也很简单，例如deleteAll<br style="line-height: normal; word-wrap: break-word" />
$where['id']&nbsp; &nbsp; =&nbsp; &nbsp;array('in','3,1,6,32,56');<br style="line-height: normal; word-wrap: break-word" />
$dao-&gt;where($where)-&gt;delete();<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">------------------------</font><br style="line-height: normal; word-wrap: break-word" />
自动验证，自动填充和toTree等方法在AdvModel<br style="line-height: normal; word-wrap: break-word" />
其中自动验证和自动填充要注意，使用1,2,3方式替代了原来的英文标识add那些<br style="line-height: normal; word-wrap: break-word" />
<br style="line-height: normal; word-wrap: break-word" />
视图模型和关联模型已从Model类分离。<br style="line-height: normal; word-wrap: break-word" />
视图模型定义进行了简化<br style="line-height: normal; word-wrap: break-word" />
<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">------------------------------</font><br style="line-height: normal; word-wrap: break-word" />
rbac 的相关配置已不在惯例配置中。<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">------------------------------</font><br style="line-height: normal; word-wrap: break-word" />
session 的使用只有 是否启用 配置，其它需要用到的配置参数要自行添加。<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">--------------------------<br style="line-height: normal; word-wrap: break-word" />
</font>模板的点语法默认是array。<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">---------------------------</font><br style="line-height: normal; word-wrap: break-word" />
插件使用方式完全改变，优化和简单并且强大起来了<br style="line-height: normal; word-wrap: break-word" />
在 项目/Lib/下，建立Widget文件夹，使用xxxWidget.class.php文件作为插件类。<br style="line-height: normal; word-wrap: break-word" />
类要继承，例如 class abcWidegt extends Widegt(){}<br style="line-height: normal; word-wrap: break-word" />
并且必须有render接口方法，public function render($data)<br style="line-height: normal; word-wrap: break-word" />
可在模板中使用W函数调用，W('abc',array('name'=&gt;'demo'))<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">-----------------------------<br style="line-height: normal; word-wrap: break-word" />
</font>文件方式缓存可以使用N级目录了。<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">-----------------------------<br style="line-height: normal; word-wrap: break-word" />
</font><font style="line-height: normal; word-wrap: break-word" color="#ff0000">html</font>标签库现在也是内置的标签库，并且可以再添加自定义的，模板中不用写了。。。（我好像还没测试这个？）<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">----------------------------</font><br style="line-height: normal; word-wrap: break-word" />
create方法使用要注意，具体查看tdweb的lite手记<br style="line-height: normal; word-wrap: break-word" />
<font style="line-height: normal; word-wrap: break-word" color="#0000ff">-----------------------------<br style="line-height: normal; word-wrap: break-word" />
</font>关于geby<br style="line-height: normal; word-wrap: break-word" />
当使用gebyXXX('aaa');时，实际上是使用了<br style="line-height: normal; word-wrap: break-word" />
$dao-&gt;where('xxx=aaa')-&gt;find();<br style="line-height: normal; word-wrap: break-word" />
<br style="line-height: normal; word-wrap: break-word" />
关于find<br style="line-height: normal; word-wrap: break-word" />
find(1)是查找id=1的数据。不能写成find('id=1')，这样会去查id='id=1'<br style="line-height: normal; word-wrap: break-word" />
要添加查询条件，可以在where(这里设置)-&gt;find();<br style="line-height: normal; word-wrap: break-word" />
<br style="line-height: normal; word-wrap: break-word" />
关于count<br style="line-height: normal; word-wrap: break-word" />
请参看总工程师的升级注意说明<br style="line-height: normal; word-wrap: break-word" />
----------------------------------<br style="line-height: normal; word-wrap: break-word" />
入口文件定义更简化<br style="line-height: normal; word-wrap: break-word" />
不用定义Think_path<br style="line-height: normal; word-wrap: break-word" />
不用定义App_name<br style="line-height: normal; word-wrap: break-word" />
不用定义app_path<br style="line-height: normal; word-wrap: break-word" />
-------------------------------<br style="line-height: normal; word-wrap: break-word" />
function.php中删除了部分核心没用到的函数。</span></span></span></span></p>
<p><span class="Apple-style-span" style="word-spacing: 0px; font: medium 'Times New Roman'; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(68,68,68); line-height: 22px; font-family: Verdana, Helvetica, Arial, sans-serif; border-collapse: collapse; text-align: left"><span class="Apple-style-span" style="word-spacing: 0px; font: medium 'Times New Roman'; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(68,68,68); line-height: 22px; font-family: Verdana, Helvetica, Arial, sans-serif; border-collapse: collapse; text-align: left"><span class="Apple-style-span" style="word-spacing: 0px; font: medium 'Times New Roman'; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(68,68,68); line-height: 22px; font-family: Verdana, Helvetica, Arial, sans-serif; border-collapse: collapse; text-align: left">字段增长改变<br style="line-height: normal; word-wrap: break-word" />
setField 取消了第4个参数$asString<br style="line-height: normal; word-wrap: break-word" />
setInc setDec 移动到AdvModel(使用时要先载入)<br style="line-height: normal; word-wrap: break-word" />
<br style="line-height: normal; word-wrap: break-word" />
实现字段增长<br style="line-height: normal; word-wrap: break-word" />
方法1：<br style="line-height: normal; word-wrap: break-word" />
$dao-&gt;where($map)-&gt;setField('Filed',array('exp','Filed+1'));<br style="line-height: normal; word-wrap: break-word" />
(注释：实质就是转到save进行处理)<br style="line-height: normal; word-wrap: break-word" />
方法2：<br style="line-height: normal; word-wrap: break-word" />
Import('AdvModel');<br style="line-height: normal; word-wrap: break-word" />
$dao-&gt;setInc('Field');<br style="line-height: normal; word-wrap: break-word" />
(注释：实质就是转到setField在转到save进行处理)<br style="line-height: normal; word-wrap: break-word" />
方法3：<br style="line-height: normal; word-wrap: break-word" />
$data['Field']=array('exp','Field+1');<br style="line-height: normal; word-wrap: break-word" />
$dao-&gt;where($map)-&gt;save($data);</span></span></span></span></span></span></p><br /><br /><a href="http://www.ax.net.cn/?action=show&amp;id=284" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.ax.net.cn/?action=show&amp;id=284</link>
			<category domain="http://www.ax.net.cn/?cid=13">thinkphp</category>
			<pubDate>2009-06-16 16:40</pubDate>
		</item>
		<item>
			<guid>http://www.ax.net.cn/?action=show&amp;id=283</guid>
			<title>thinkphp模型的自动验证</title>
			<author>admin</author>
			<description><![CDATA[<p><span class="Apple-style-span" style="word-spacing: 0px; font: medium 'Times New Roman'; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(68,68,68); line-height: 22px; font-family: Verdana, Helvetica, Arial, sans-serif; border-collapse: collapse; text-align: left">我们提交或者更改<span class="t_tag" style="cursor: pointer; line-height: normal; border-bottom: rgb(255,0,0) 1px solid; white-space: nowrap; word-wrap: break-word" onclick="tagshow(event)" href="tag.php?name=%E6%95%B0%E6%8D%AE">数据</span>库资料的时候，可以使用Model进行自动验证，其中，有一些验证格式可以拿来就用的，不用自己单独写正则<br style="line-height: normal; word-wrap: break-word" />
<div class="codeText">
<div class="codeHead">PHP代码</div>
<ol class="dp-c">
    <li class="alt"><span><span class="keyword">static</span><span>&nbsp;</span><span class="vars">$regex</span><span>&nbsp;=&nbsp;</span><span class="keyword">array</span><span>( &nbsp;&nbsp;</span></span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'require'</span><span>=&gt;&nbsp;</span><span class="string">'/.+/'</span><span>,&nbsp;</span><span class="comment">//匹配任意字符，除了空和断行符 </span><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'email'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/'</span><span>, &nbsp;&nbsp;</span></li>
</ol>
</div>
</span></span></p>
<div class="codeText">
<ol class="dp-c">
    <li class="alt">&nbsp;</li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'phone'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/'</span><span>, &nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'mobile'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/'</span><span>, &nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'url'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&amp;_~`@[\]\':+!]*([^&lt;&gt;\&quot;\&quot;])*$/'</span><span>, &nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'currency'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/^\d+(\.\d+)?$/'</span><span>, &nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'number'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/\d+$/'</span><span>, &nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'zip'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/^[1-9]\d{5}$/'</span><span>, &nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'qq'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/^[1-9]\d{4,12}$/'</span><span>, &nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'integer'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/^[-\+]?\d+$/'</span><span>, &nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'double'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/^[-\+]?\d+(\.\d+)?$/'</span><span>, &nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">'english'</span><span>&nbsp;=&gt;&nbsp;</span><span class="string">'/^[A-Za-z]+$/'</span><span>, &nbsp;&nbsp;</span></li>
    <li class=""><span>);&nbsp;&nbsp;</span></li>
</ol>
</div>
<p><br style="line-height: normal; word-wrap: break-word" />
说的很清楚，不多讲了<br style="line-height: normal; word-wrap: break-word" />
另外一个需要注意的是，如果我们需要使用正则表达式认证：</p>
<div class="codeText">
<div class="codeHead">PHP代码</div>
<ol class="dp-c">
    <li class="alt"><span><span class="keyword">var</span><span>&nbsp;</span><span class="vars">$_validate</span><span>=</span><span class="keyword">array</span><span>( &nbsp;&nbsp;</span></span></li>
    <li class=""><span class="keyword">array</span><span>(</span><span class="string">'name'</span><span>,</span><span class="string">'require'</span><span>,</span><span class="string">'姓名必须填写！'</span><span>), &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="keyword">array</span><span>(</span><span class="string">'banji'</span><span>,</span><span class="string">'require'</span><span>,</span><span class="string">'班级必须填写！'</span><span>), &nbsp;&nbsp;</span></li>
    <li class=""><span class="keyword">array</span><span>(</span><span class="string">'jiguan'</span><span>,</span><span class="string">'require'</span><span>,</span><span class="string">'籍贯必须填写！'</span><span>), &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="keyword">array</span><span>(</span><span class="string">'rtsj'</span><span>,</span><span class="string">'/^\d{4}\-\d{1,2}-\d{1,2}$/'</span><span>,</span><span class="string">'入团时间格式错误！'</span><span>), &nbsp;&nbsp;</span></li>
    <li class=""><span class="keyword">array</span><span>(</span><span class="string">'rtdd'</span><span>,</span><span class="string">'require'</span><span>,</span><span class="string">'入团地点必须填写！'</span><span>), &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="keyword">array</span><span>(</span><span class="string">'birthday'</span><span>,</span><span class="string">'/^\d{4}\-\d{1,2}-\d{1,2}$/'</span><span>,</span><span class="string">'出生年月格式错误！'</span><span>), &nbsp;&nbsp;</span></li>
    <li class=""><span class="keyword">array</span><span>(</span><span class="string">'qianfarq'</span><span>,</span><span class="string">'/^\d{4}\-\d{1,2}-\d{1,2}$/'</span><span>,</span><span class="string">'签发日期格式错误！'</span><span>), &nbsp;&nbsp;</span></li>
    <li class="alt"><span class="keyword">array</span><span>(</span><span class="string">'bianhao'</span><span>,</span><span class="string">'require'</span><span>,</span><span class="string">'团员编号必须填写！'</span><span>), &nbsp;&nbsp;</span></li>
</ol>
</div>
<p>别忘了在正则表达式两边都有&quot;/&quot;，要不然认证不通过</p><br /><br /><a href="http://www.ax.net.cn/?action=show&amp;id=283" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.ax.net.cn/?action=show&amp;id=283</link>
			<category domain="http://www.ax.net.cn/?cid=13">thinkphp</category>
			<pubDate>2009-06-16 16:22</pubDate>
		</item>
		<item>
			<guid>http://www.ax.net.cn/?action=show&amp;id=240</guid>
			<title>给THINKPHP换个list标签</title>
			<author>admin</author>
			<description><![CDATA[<p>thinkphp的标签其实就是把一截PHP与HTML结合的代码用一个简单的标签代替。</p>
<p>常用的当然就是html:list啦。</p>
<p>用是好用，系统UI丑了点。</p>
<p>下面来新建个clist标签，吧原来的table换成css+div的。</p>
<p>这里用的是1.5版的。</p>
<p>进入thinkphp的Lib\Think\Template\TagLib目录</p>
<p>第一步：打开TagLibHtml.class.php在倒数第三行加入代码</p>
<p>&nbsp;</p>
<p>第二步：打开thinkphp目录下的Lib\Think\Template\Tags\html.xml在倒数第二行加入</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>第三步：给要用到标签的页面加上CSS</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>第四步：使用</p>
<p>&nbsp;</p>
<div class="codeText">
<div class="codeHead">XML/HTML代码</div>
<ol class="dp-xml">
    <li class="alt"><span><span class="tag">&lt;</span><span class="tag-name">html:clist</span><span>&nbsp;</span><span class="attribute">id</span><span>=</span><span class="attribute-value">&quot;checkList&quot;</span><span>&nbsp;</span><span class="attribute">checkbox</span><span>=</span><span class="attribute-value">&quot;true&quot;</span><span>&nbsp;</span><span class="attribute">action</span><span>=</span><span class="attribute-value">&quot;true&quot;</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">&quot;list&quot;</span><span>&nbsp;</span><span class="attribute">style</span><span>=</span><span class="attribute-value">&quot;iic_list&quot;</span><span>&nbsp;</span><span class="attribute">datasource</span><span>=</span><span class="attribute-value">&quot;list&quot;</span><span>&nbsp;</span><span class="attribute">show</span><span>=</span><span class="attribute-value">&quot;id::编号|50px,name::标题|57%::appshow,ctime|toDate='Y-m-d/H:i:s'::时间|18%&quot;</span><span>&nbsp;</span><span class="attribute">actionlist</span><span>=</span><span class="attribute-value">&quot;appedit:修改,appdel:删除&quot;</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li>
</ol>
</div>
<p>其中id为dl标签的id；checkbox为复选框选项；action为是否显示功能操作；name为VO对象名；datasource就是你数据源数组的名字；show为要显示的对象字段；在这里我使用双冒号分隔以便显示时间里面的冒号（字段::别名|宽度）；</p>
<p>暂时就记这么多吧。代码记在详细页面。</p><br /><br /><a href="http://www.ax.net.cn/?action=show&amp;id=240" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.ax.net.cn/?action=show&amp;id=240</link>
			<category domain="http://www.ax.net.cn/?cid=13">thinkphp</category>
			<pubDate>2009-05-27 01:51</pubDate>
		</item>
		<item>
			<guid>http://www.ax.net.cn/?action=show&amp;id=200</guid>
			<title>开始使用THINKPHP啦</title>
			<author>admin</author>
			<description><![CDATA[<p>从thinkphp的0.98版起偶便开始注意这个国内的开源PHP框架了，没别的原因，就因为它开源、强大、国产。</p>
<p>但是一个框架的强大与其复杂往往都是成正比的，thinkphp也不列外，为了使它好好地为偶工作，偶没少花时间看文档。</p>
<p>这里记录偶学习的点点滴滴。</p>
<p>详细就看全文吧。</p><br /><br /><a href="http://www.ax.net.cn/?action=show&amp;id=200" target="_blank">阅读全文</a><br /><br />]]></description>
			<link>http://www.ax.net.cn/?action=show&amp;id=200</link>
			<category domain="http://www.ax.net.cn/?cid=13">thinkphp</category>
			<pubDate>2008-04-16 10:48</pubDate>
		</item>
	</channel>
</rss>
