<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>IT狂人的博客</title>
	<atom:link href="http://www.yinzhili.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.yinzhili.com</link>
	<description>世界上有10种人:一种是懂二进制的，另一种是不懂的。</description>
	<lastBuildDate>Tue, 02 Mar 2010 04:53:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>在Windows下编译适用于PHP 5.2.12及5.2.13的eAccelerator.dll(附下载)</title>
		<link>http://www.yinzhili.com/2010/02/build-eaccelerator-for-php-5-2-12-or-5-2-13-on-windows.html</link>
		<comments>http://www.yinzhili.com/2010/02/build-eaccelerator-for-php-5-2-12-or-5-2-13-on-windows.html#comments</comments>
		<pubDate>Fri, 26 Feb 2010 08:10:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[eaccelerator]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.yinzhili.com/?p=145</guid>
		<description><![CDATA[最近PHP 5.2.12及5.2.13发布了，修复了多个bug，因此升级到这一版本是非常必要的。
首先说明一下我的一些参数：
操作系统: Windows 7 Ultimate
Web Server：Apache 2.2.14
Visual Studio: 6.0 (别嫌弃它版本老，即便是在Win7下[......]<p class='read-more'><a href='http://www.yinzhili.com/2010/02/build-eaccelerator-for-php-5-2-12-or-5-2-13-on-windows.html'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>最近PHP 5.2.12及5.2.13发布了，修复了多个bug，因此升级到这一版本是非常必要的。</p>
<p>首先说明一下我的一些参数：<br />
操作系统: Windows 7 Ultimate<br />
Web Server：Apache 2.2.14<br />
Visual Studio: 6.0 (别嫌弃它版本老，即便是在Win7下它还是能用的，当然你用Visual Studio 2008也行)</p>
<p>什么是eAccelerator？<br />
eaccelerator是一个自由开放源码php加速器，优化和动态内容缓存，提高了性能php脚本的缓存性能，使得PHP脚本在编译的状态下，对服务器的开销几乎完全消除。 它还有对脚本起优化作用，以加快其执行效率。</p>
<p>1.首先下载编译好的PHP二进制包。(稍后会用到) 地址如下：<br />
<span style="color: #3366ff;">http://cn.php.net/distributions/php-5.2.12-Win32.zip</p>
<p>http://cn.php.net/distributions/php-5.2.13-Win32.zip</span></p>
<p>2.再下载PHP的源代码，稍后编译eAccelerator的时候会用到。地址如下：<br />
<span style="color: #3366ff;">http://cn2.php.net/get/php-5.2.12.tar.bz2/from/a/mirror</p>
<p>http://cn2.php.net/get/php-5.2.13.tar.bz2/from/a/mirror</span></p>
<p>3.升级PHP：<br />
这一过程很简单，首先关闭Apache，然后将压缩包里解压出来的所有文件替换掉原来的文件即可。例如你原来的PHP程序文件位于 D:\php，那么请将php-5.2.13-Win32.zip(或者php-5.2.12-Win32.zip)解压到这一路径下覆盖原有文件。</p>
<p>4.启动Apache，我们会收到一条报错信息，Apache无法启动。打开Apache的日志文件(此文件路径为apache\logs\error.log)，我们会看到这样的提示信息：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">PHP Warning<span style="color: #339933;">:</span>  <span style="color: #009900;">&#91;</span>eAccelerator<span style="color: #009900;">&#93;</span> This build of <span style="color: #0000ff;">&quot;eAccelerator&quot;</span> was compiled <span style="color: #b1b100;">for</span> PHP version 5<span style="color: #339933;">.</span>2<span style="color: #339933;">.</span>11<span style="color: #339933;">.</span>
Rebuild it <span style="color: #b1b100;">for</span> your PHP version <span style="color: #009900;">&#40;</span>5<span style="color: #339933;">.</span>2<span style="color: #339933;">.</span>13<span style="color: #009900;">&#41;</span> or download precompiled binaries<span style="color: #339933;">.</span></pre></div></div>

<p>意思就是当前的eAccelerator是为PHP 5.2.11编译的，不适用于5.2.13。我们应该重新编译一份eAccelerator。</p>
<p>5.下载一份eAccelerator的源码。地址如下：<br />
<span style="color: #3366ff;">http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.zip</span></p>
<p>6.将第2步骤下载到的PHP源码解压到某一目录下，例如 E:\php。然后打开你的PHP程序目录(也就是你的php.exe所在的目录)，找到其中dev子目录下的php5ts.lib文件，把它复制到E:\php这一位置。</p>
<p>7.打开E:\php\ext，在这下面创建一个目录命名为eaccelerator，然后将第5步骤下载到的压缩包解压到此目录下。此时的目录结构应该是这样的：</p>
<div id="attachment_146" class="wp-caption aligncenter" style="width: 198px"><a href="http://www.yinzhili.com/wp-content/uploads/2009/12/1.png"><img class="size-medium wp-image-146" title="图1" src="http://www.yinzhili.com/wp-content/uploads/2009/12/1.png" alt="图1" width="188" height="502" /></a><p class="wp-caption-text">图1</p></div>
<p>8.打开win32子目录，其中应该有一个名叫eAccelerator.dsw的项目文件，用VS开发环境打开它(比如我用的就是VS6.0)，打开&#8221;组件&#8221;&gt;&#8221;配置&#8221;，选中 Win32 Release PHP5 这一选项，单击“关闭”。</p>
<div id="attachment_147" class="wp-caption aligncenter" style="width: 456px"><a href="http://www.yinzhili.com/wp-content/uploads/2009/12/2.png"><img class="size-medium wp-image-147" title="图2" src="http://www.yinzhili.com/wp-content/uploads/2009/12/2.png" alt="图2" width="446" height="228" /></a><p class="wp-caption-text">图2</p></div>
<p>9.按下F7键(或选择工具条中的编辑按钮)开始编译，稍等片刻，编译成功，你就可以在win32目录下看到生成了一个Release子目录，打开这个子目录，你就会看到已经生成了eAccelerator.dll文件。<br />
将这个文件复制到你的PHP扩展目录下(如D:\php\ext)，替换掉原有的文件，然后启动Apache，你就会发现eAccelerator已经成功加载了。</p>
<div id="attachment_148" class="wp-caption aligncenter" style="width: 615px"><a href="http://www.yinzhili.com/wp-content/uploads/2009/12/3.png"><img class="size-full wp-image-148" title="图3" src="http://www.yinzhili.com/wp-content/uploads/2009/12/3.png" alt="图3" width="605" height="258" /></a><p class="wp-caption-text">图3</p></div>
<h3>或者</h3>
<p><a href="http://www.yinzhili.com/downloads/binary/eAccelerator_dll_for_php_5_2_13.zip">猛击此处下载编译好的dll文件</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yinzhili.com/2010/02/build-eaccelerator-for-php-5-2-12-or-5-2-13-on-windows.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>通过伪造Referer来解决外链问题</title>
		<link>http://www.yinzhili.com/2010/01/the-anti-leech-issue-and-referer.html</link>
		<comments>http://www.yinzhili.com/2010/01/the-anti-leech-issue-and-referer.html#comments</comments>
		<pubDate>Fri, 08 Jan 2010 07:47:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[外链]]></category>
		<category><![CDATA[盗链]]></category>

		<guid isPermaLink="false">http://www.yinzhili.com/?p=163</guid>
		<description><![CDATA[什么是Referer?
Referer是HTTP Header的一个字段，当浏览器向服务器发送请求的时候一般会包含Referer信息，这一字段保存的是访客的来源URI。
以PHP为例，通过输出$_SERVER变量，你就可以看到HTTP_REFERER信息：
<a href="http://www.yinzhili.com/wp-content/uploads/2010/01/01.png"><img src="http://www.yinzhili.com/wp-content/uploads/2010/01/01.png" alt="图1" title="图1" width="499" height="197" class="size-full wp-image-164" /></a>图1
如今很多知名的网络相册(如网易相册、[......]<p class='read-more'><a href='http://www.yinzhili.com/2010/01/the-anti-leech-issue-and-referer.html'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>什么是Referer?<br />
Referer是HTTP Header的一个字段，当浏览器向服务器发送请求的时候一般会包含Referer信息，这一字段保存的是访客的来源URI。</p>
<p>以PHP为例，通过输出$_SERVER变量，你就可以看到HTTP_REFERER信息：<br />
<div id="attachment_164" class="wp-caption aligncenter" style="width: 509px"><a href="http://www.yinzhili.com/wp-content/uploads/2010/01/01.png"><img src="http://www.yinzhili.com/wp-content/uploads/2010/01/01.png" alt="图1" title="图1" width="499" height="197" class="size-full wp-image-164" /></a><p class="wp-caption-text">图1</p></div></p>
<p>如今很多知名的网络相册(如网易相册、百度相册、51相册等等)都限制了外链，我不知道它们用什么方式实现，但是目前而言大多数防盗链的机制都是基于对Referer的判断来实现的。<br />
比如说，我有一个网站，其中一个页面地址是 http://example.com/test.html，里面需要外链一张猫扑的图片，因此，image.html里面可以这么写：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;http://upload3.mop.com/upload3/2009/12/18/08/1261139622733.jpg&quot;/&gt;</pre></td></tr></table></div>

<p>但是我们会发现这样外链的图片是无法显示出来的。原因在于，当我们访问http://example.com/test.html时，浏览器会向upload3.mop.com也就是猫扑的服务器发送一个请求，这一请求中包含的Referer信息应该就是这样：</p>
<p>http://example.com/test.html</p>
<p>这样，猫扑的服务器就可以判断出这是一个来自外部网站的请求，从而予以拒绝，这样我们就无法显示这张图片了。</p>
<p>那么，应该如何解决这一问题呢? 用火狐浏览器的可能知道，火狐有个插件叫做RefControl，可以用它来伪造Referer，从而正常显示图片。但是如果你是站长，你总不能要求你的访客都使用火狐浏览器对吧？即便你所有的访客都使用火狐浏览器，你也很难保证他们都安装了RefControl这个插件。<br />
这样，我们只能从程序方面入手解决问题：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$img</span><span style="color: #339933;">=</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$host</span><span style="color: #339933;">=</span><span style="color: #000088;">$path</span><span style="color: #339933;">=</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$host</span><span style="color: #339933;">=</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$host</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$host</span><span style="color: #339933;">=</span><span style="color: #000088;">$host</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$path</span><span style="color: #339933;">=</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fsockopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #339933;">@</span><span style="color: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;GET <span style="color: #006699; font-weight: bold;">$path</span> HTTP/1.1<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">@</span><span style="color: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Host: <span style="color: #006699; font-weight: bold;">$host</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">@</span><span style="color: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Accept: */*<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">@</span><span style="color: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Referer: http://<span style="color: #006699; font-weight: bold;">$host</span>/<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">@</span><span style="color: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">@</span><span style="color: #990000;">fputs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Connection: Close<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$Content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4096</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$Content</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
<span style="color: #339933;">@</span><span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pos</span><span style="color: #339933;">=</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Content</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$head</span><span style="color: #339933;">=</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Content</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$pos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$text</span><span style="color: #339933;">=</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$Content</span><span style="color: #339933;">,</span><span style="color: #000088;">$pos</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$head</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>实际上这就是通过伪造Referer来实现我们想要的效果。<br />
我们把这段程序保存为redirect.php，放到服务器上，例如http://example.com/redirect.php，那么，接下来我们只需要将原来的外链图片地址经由这段程序处理，就可以正常显示。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;http://example.com/redirect.php?url=http://upload3.mop.com/upload3/2009/12/18/08/1261139622733.jpg&quot;/&gt;</pre></td></tr></table></div>

<p>效果如下：<br />
<div id="attachment_165" class="wp-caption aligncenter" style="width: 368px"><a href="http://www.yinzhili.com/wp-content/uploads/2010/01/02.png"><img src="http://www.yinzhili.com/wp-content/uploads/2010/01/02.png" alt="图2" title="图2" width="358" height="427" class="size-full wp-image-165" /></a><p class="wp-caption-text">图2</p></div></p>
<p>由此可见，Referer信息不一定可靠，因为它是可以伪造出来的，通过这一手段来防盗链并不是一个完美的办法。<br />
同时，我们也应该尽可能少的外链文件，毕竟大多数服务器都有带宽的限制和成本的考虑，限制外链对它们的生存也是很重要的。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yinzhili.com/2010/01/the-anti-leech-issue-and-referer.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress常用时间参数</title>
		<link>http://www.yinzhili.com/2010/01/wordpress-time-parameters.html</link>
		<comments>http://www.yinzhili.com/2010/01/wordpress-time-parameters.html#comments</comments>
		<pubDate>Sat, 02 Jan 2010 05:01:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.yinzhili.com/?p=161</guid>
		<description><![CDATA[使用Wordpress国外主题的时候常常要改动其中的时间参数，因为老外他们使用的时间格式和我们大不一样，比如说同样是一个日期：2010年1月2日，美国英语里面可能写成 Jan 2nd 2010，英国英语里则是 2nd Jan 2010，而我们汉语里是 2010年1月2日。好在Wordpress提供了[......]<p class='read-more'><a href='http://www.yinzhili.com/2010/01/wordpress-time-parameters.html'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>使用Wordpress国外主题的时候常常要改动其中的时间参数，因为老外他们使用的时间格式和我们大不一样，比如说同样是一个日期：2010年1月2日，美国英语里面可能写成 Jan 2nd 2010，英国英语里则是 2nd Jan 2010，而我们汉语里是 2010年1月2日。好在Wordpress提供了很多时间参数，用户可以输出自定义的日期，这一点和PHP里面的date函数有点类似。</p>
<p>下面是一些常用的参数：</p>
<p>* a代表小写的英语的上下午，如am、pm<br />
* A代表大写的英语的上下午，如AM、PM<br />
* d代表英语的日期（小于10仍为两位数写法），如05、12<br />
* D代表中文的星期，如五、七<br />
* F代表中文的月份（包括“月”这个字），如五月、十二月<br />
* g代表英语的小时（小于10为一位数写法），如5、12<br />
* G代表英语的小时（小于10仍为两位数写法），如05、12<br />
* h代表英语的分钟（小于10为一位数写法），如5、12<br />
* H代表英语的分钟（小于10仍为两位数写法），如05、12<br />
* j代表英语的日期（小于10为一位数写法），如08-02-09<br />
* l代表中文的星期（包括“星期”这两个字），如星期五、星期七<br />
* m代表英语的月份（小于10仍为两位数写法），如05、12<br />
* M代表英语的月份（以单词的形式显示），如Jun<br />
* n代表英语的月份（小于10为一位数写法），如5、12<br />
* O代表英语的时区，如+0800<br />
* r代表完整的日期时间，如Tue, 06 Jun 2006 18:37:11 +0800<br />
* S代表日期的序数后缀，如st、th<br />
* T代表英语的时区（以单词的形式显示），如CST<br />
* w代表英语的星期，如5、7<br />
* W代表周数，如23<br />
* y代表两位数年份，如07、08<br />
* Y代表四位数年份，如2007、2008<br />
* z代表天数，如156</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yinzhili.com/2010/01/wordpress-time-parameters.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>100条超级残暴的英文翻译</title>
		<link>http://www.yinzhili.com/2009/12/100-brilliant-translations.html</link>
		<comments>http://www.yinzhili.com/2009/12/100-brilliant-translations.html#comments</comments>
		<pubDate>Fri, 11 Dec 2009 07:06:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[翻译]]></category>

		<guid isPermaLink="false">http://www.yinzhili.com/?p=143</guid>
		<description><![CDATA[1、Do not argue with an idiot. He will drag you down to his level and beat you with experience.
你永远不能战胜一个纯SB,因为他会把你的智商拉到跟他个水平,然后用丰富的经验打败你
2、I asked God[......]<p class='read-more'><a href='http://www.yinzhili.com/2009/12/100-brilliant-translations.html'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>1、Do not argue with an idiot. He will drag you down to his level and beat you with experience.<br />
你永远不能战胜一个纯SB,因为他会把你的智商拉到跟他个水平,然后用丰富的经验打败你</p>
<p>2、I asked God for a bike, but I know God doesn’t work that way. So I stole a bike and asked for forgiveness.<br />
开始我直接求上帝赐辆自行车。 后来我琢磨上帝办事儿不是这个路数。 于是老子偷了一辆然后求上帝宽恕。</p>
<p>3、I want to die peacefully in my sleep, like my grandfather.. Not screaming and yelling like the passengers in his car.<br />
我希望能像爷爷那样，安静地在睡梦中死去…… 而不是要像他开的车上那些惨叫滴乘客一样死法啊！</p>
<p>4、If 4 out of 5 people SUFFER from diarrhea… does that mean that one enjoys it?<br />
如果4/5的人在忍受腹泻的痛苦，那剩下1/5咋回事？很享受吗？</p>
<p>5、We live in a society where pizza gets to your house before the police.<br />
在咱们这噶哒送外卖的都比警察来的快.</p>
<p>6、I thought I wanted a career, turns out I just wanted paychecks.<br />
曾以为我想要的是职业，结果发现我只是想要工资。</p>
<p>7、Light travels faster than sound. This is why some people appear bright until you hear them speak.<br />
光总是比声音跑的快点….这就是为嘛有些SB只有在开口说话之后你才发现他是在装B…</p>
<p>8、Remember, if you smoke after sex you’re doing it too fast.<br />
记着，如果你在嘿咻后冒烟了，证明你整得太快了。</p>
<p>9、I saw a woman wearing a sweat shirt with “Guess” on it…so I said “Implants?”<br />
瞅见个姐姐，胸前衣服上写着“Guess”…俺就问了一句：“…隆过？”</p>
<p>10、The last thing I want to do is hurt you. But it’s still on the list.<br />
直译：在这个世界上,我最不愿意做的事就是伤害你,但是这件事仍在我的考虑之列。<br />
意译a：我真不想伤害你，但你也别逼我。<br />
意译b：吾虽不杀伯仁，伯仁由我而死。</p>
<p>11、If sex is a pain in the ass, then you’re doing it wrong…<br />
a. 如觉嘿咻乃屁眼不能承受之痛，那是你操错洞…<br />
b. 若XXOO是下体的痛，那么，是你操错。</p>
<p>12、The early bird might get the worm, but the second mouse gets the cheese.<br />
a. 早起滴小鸟有虫虫！晚到的老鼠有奶酪！<br />
b. 早起的鸟儿有虫吃，早起的虫儿被鸟吃。</p>
<p>13、Having sex is like playing bridge. If you don’t have a good partner, you’d better have a good hand.<br />
XXOO就象打桥牌。 如果对手不好使，自己的手必须好使。</p>
<p>14、 Some people are like Slinkies … not really good for anything, but you can’t help smiling when you see one tumble down the stairs.<br />
有些人就像 Slinkies （弹簧玩具），没什么实在用处，但看他们在楼梯上倒腾来捣腾去还是很有喜感。</p>
<p>15、Politicians and diapers have one thing in common. They should both be changed regularly, and for the same reason.<br />
政客和纸尿布有一个共同点就是：他们都很有规律地被替换，而且因为同一个理由——脏了！！</p>
<p>16、War does not determine who is right – only who is left.<br />
战争不能决出正义，但能判出哪方出局。</p>
<p>17、Women might be able to fake orgasms. But men can fake a whole relationship.<br />
a. 女人的高潮可能是装出来的。但是男人TMD可以整段感情都是装出来的！<br />
b. 女人假装高潮以获取真实的感情；男人假装感情以获取真实的高潮。</p>
<p>18、We never really grow up, we only learn how to act in public.<br />
我们永远不可能真正的成熟，我们只是学会在众人面前装逼。</p>
<p>19、Men have two emotions: Hungry and Horny. If you see him without an erection, make him a sandwich.<br />
男人就两种状态：饿 和 性饥渴。 要是他不硬，就给他个三明治！</p>
<p>20、My mother never saw the irony in calling me a son-of-a-bitch.<br />
我妈每次对着我骂草泥马的时候都没看出其中笑点。</p>
<p>21、If you think nobody cares if you’re alive, try missing a couple of payments.<br />
你要是觉得没人在乎你的死活,那你不妨尝试一下跟你的债主玩躲猫猫~~</p>
<p>22、Sex is not the answer. Sex is the question. “Yes” is the answer.<br />
XXOO并不是结论而是个问题…爽不爽才是答案…</p>
<p>23、Evening news is where they begin with ‘Good evening’, and then proceed to tell you why it isn’t.<br />
晚间新闻总是以“晚上好”开头，再告诉你你为什么好不了。</p>
<p>24、How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?<br />
直译：一根火柴能点着整片森林，一盒火柴也生不起个营火，这咋回事！<br />
意译：想当年哥戴套都能让人怀孕，看今朝叔竟然去看男科</p>
<p>25、Knowledge is knowing a tomato is a fruit; Wisdom is not putting it in a fruit salad.<br />
直译：知识就是说你知道西红柿是一种水果；智慧就好似不要把它放进水果沙拉里。<br />
意译a：知识就是告诉你说应该把鸡蛋放进篮子，智慧则是叫你不要把所有鸡蛋都放进一个篮子。<br />
意译b:所谓知识就是知道韩少和小四都属于80后，但智慧告诉你这终还是男女有别~</p>
<p>26、If God is watching us, the least we can do is be entertaining.<br />
上帝瞅着咱们呢，大伙好歹喜感点吧！</p>
<p>27、Never, under any circumstances, take a sleeping pill and a laxative on the same night.<br />
无论，在任何情况下，永远，不要在一个夜晚，同时吃，安眠药，和通便灵。</p>
<p>28、I didn’t fight my way to the top of the food chain to be a vegetarian<br />
老子拼死拼活奋斗到食物链顶端，不是为了成为一个素食者。</p>
<p>29、A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station..<br />
公车站呀公车停。火车站呀火车停。俺桌上有个工作站…</p>
<p>30、If I agreed with you we’d both be wrong.<br />
要是我听你的，咱俩就都2B了。</p>
<p>31、 Did you know that dolphins are so smart that within a few weeks of captivity, they can train people to stand on the very edge of the pool and throw them fish?<br />
海豚可聪明了你知道不？只要驯养几个星期，它们就能让人类乖乖站在池边给它们扔鱼吃了。</p>
<p>32、A computer once beat me at chess, but it was no match for me at kick boxing.<br />
a. 下棋，我不行；玩跆拳道，电脑不行！<br />
b. 下象棋电脑把我玩得团团转，拳击我能把机箱踹得七零八散！</p>
<p>33、When tempted to fight fire with fire, remember that the Fire Department usually uses water.<br />
以暴治暴，不如以抱治爆。</p>
<p>34、 Children: You spend the first 2 years of their life teaching them to walk and talk. Then you spend the next 16 years telling them to sit down and shut-up.<br />
孩子就是：你先花2年，教丫们走路和说话。然后你再花16年教丫们坐定和闭嘴。</p>
<p>35、Why does someone believe you when you say there are four billion stars, but check when you say the paint is wet?<br />
为什么当你说天上有400亿星星时他不怀疑，却偏要检查你所说的“油漆未干”？</p>
<p>36、Better to remain silent and be thought a fool, than to speak and remove all doubt.<br />
a. 宁愿闭嘴当傻瓜，也别学乌鸦乱呱呱。<br />
b. 越解释越SB，不说话最NB。<br />
c. 剽悍的人生不需要解释<br />
d. 宁可闭口被人当SB，也不张口解释所有疑。</p>
<p>37、A bank is a place that will lend you money, if you can prove that you don’t need it.<br />
银行就是当你证明了你不需要钱的时候可以借钱给你的地方</p>
<p>38、Laugh at your problems, everybody else does.<br />
a.对你的问题哈哈大笑吧，别人都在这么做。<br />
b. 你有什么不开心的？说出来给大家开心开心。</p>
<p>39、The voices in my head may not be real, but they have some good ideas!<br />
a. 我知道没人在我脑子里跟我聊天，但那些话真TM有用！<br />
b. 我幻想的低吟不一定是真的，但足够让我意淫</p>
<p>40、A clear conscience is usually the sign of a bad memory.<br />
a. 无愧于心哈？记性不好吧？<br />
意译b： 自从那次在人妖身边醒来，每次去夜店我都提醒自己“一定要戴眼镜……”<br />
c. 意识清醒了，意味着不堪回首了。</p>
<p>41、Good girls are bad girls that never get caught.<br />
a. 所谓的好姑娘，咳！就是还没被群众抓到的JP女·····<br />
b. 想立牌坊就得会装</p>
<p>42、He who smiles in a crisis has found someone to blame.<br />
临危忽然微笑的那谁，定是找到替罪羊鸟~</p>
<p>43、Women will never be equal to men until they can walk down the street with a bald head and a beer gut, and still think they are sexy.<br />
如果女人能做到以秃顶和啤酒肚在大街上晃还觉得自己倍儿性感——此时估计男女能平等。</p>
<p>44、The shinbone is a device for finding furniture in a dark room.<br />
小腿上的骨头——在黑房间里找准家具位置的好装备。</p>
<p>45、The main reason Santa is so jolly is because he knows where all the bad girls live.<br />
圣诞老人当然美，他知道所有YD妞住哪儿啊！</p>
<p>46、To steal ideas from one person is plagiarism. To steal from many is research.<br />
剽窃一个人的叫剽窃，剽窃许多人的叫研究。<br />
意译：窃钩者诛，窃国者为诸侯。</p>
<p>47、Some cause happiness wherever they go. Others whenever they go.<br />
有些人一来大家就开心了；有些人一走大家就开心了。.</p>
<p>48、I discovered I scream the same way whether I’m about to be devoured by a great white shark or if a piece of seaweed touches my foot.<br />
我发现，我滴脚丫被一小片儿海藻擦过时，我滴那个惨叫声——和我被大白鲨吓坏时的惨叫声是一样滴。</p>
<p>49、Crowded elevators smell different to midgets.<br />
直译：你若是挤满人的电梯里的小矮人，肯定能嗅出不同的味儿。<br />
意译：灵感来自于所站的角度与众不同。</p>
<p>50、I didn’t say it was your fault, I said I was blaming you.<br />
我可没怨你！我是在谴责你！</p>
<p>51、Whenever I fill out an application, in the part that says “If an emergency, notify:” I put “DOCTOR”. What’s my mother going to do?<br />
当我填表的时候，有一项是“紧急情况联系：” 我填上了“医生”，到时候我妈能帮上什么忙？！</p>
<p>52、God must love stupid people. He made SO many.<br />
上帝一定倍儿爱SB，不然他造这么多！！！！！！！</p>
<p>53、Behind every successful man is his woman. Behind the fall of a successful man is usually another woman.<br />
每一个成功的男人背后都有一个女人。每一个翻了船的成功男人背后往往是另一个女人。</p>
<p>54、I always take life with a grain of salt, …plus a slice of lemon, …and a shot of tequila.<br />
生活对于我来说是小菜一碟，我通常就着盐和柠檬，再来一小杯烈性酒。<br />
意译a：生活，是一团麻……绳，……再加一根蜡烛……一柄皮鞭。<br />
意译b: 生活，不就是先狂吃菜，然后把烈性白酒一饮而尽？</p>
<p>55、The sole purpose of a child’s middle name, is so he can tell when he’s really in trouble.<br />
直译：小孩子要中间名，纯粹是为了让他知道他啥时候真的有麻烦了。<br />
直译a：起个全名就为了揍孩子前可以底气十足地喊出来。<br />
意译b：贾君鹏这名字就为了让他妈喊他回家吃饭！</p>
<p>56、It’s not the fall that kills you; it’s the sudden stop at the end.<br />
跳楼的时候，“啊——”的时候还没死，“啪！”那才是死了。</p>
<p>57、Artificial intelligence is no match for natural stupidity.<br />
人工智能从来敌不过天然请勿使用不良词语。</p>
<p>58、Never hit a man with glasses. Hit him with a baseball bat.<br />
直译：不要用眼镜腿来打男人，用棒球击杆。<br />
意译: 要下手就得狠，甭来毛毛雨。</p>
<p>59、There’s a fine line between cuddling and holding someone down so they can’t get away.<br />
直译：要想留住谁，在抱摔的时候有一条细线区分出你是否为高手。<br />
b：抱摔是留不住女人的，搂抱才管用。/抱和爆是有区别的。 /推倒和拥抱是有微妙的区别的哟！/拥抱和柔道里的压制是有区别的！</p>
<p>60、A bargain is something you don’t need at a price you can’t resist.<br />
所谓砍价，就是这东西虽然你不需要，但价格太好必须要买下来！</p>
<p>61、Never get into fights with ugly people, they have nothing to lose.<br />
绝对不要和长得丑的争执，他们已经没什么可输的了。</p>
<p>62、You do not need a parachute to skydive. You only need a parachute to skydive twice.<br />
过了河也别拆桥，没准你还要回来呢。</p>
<p>63、The difference between an oral thermometer and a rectal thermometer is in the taste.<br />
口腔体温计和菊花体温计有啥不同？尝尝看就知道了</p>
<p>64、My opinions may have changed, but not the fact that I am right.<br />
我的观点或许改变了，但我是正确的这一事实却亘古不变。<br />
意译：我们要搞共产主义，也要搞有中国特色的社会主义。</p>
<p>65、My psychiatrist told me I was crazy and I said I want a second opinion. He said okay, you’re ugly too.<br />
心理医师：你神经病！！！ 我：能说点别的吗？<br />
心理医师：好！！而且你真TM丑！！！</p>
<p>66、A little boy asked his father, “Daddy, how much does it cost to get married?” Father replied, “I don’t know son, I’m still paying.”<br />
一单纯傻儿子问他爹：“爸，结婚到底要花多少钱啊？”他爸说：“儿啊，我真不知道…没看见我还在交钱吗？”</p>
<p>67、 Some people say “If you can’t beat them, join them”. I say “If you can’t beat them, beat them”, because they will be expecting you to join them, so you will have the element of surprise.<br />
有人说“打不过，就合作”。我说“打不过，也要打”。因为丫们指望你加入，得来点惊喜~！</p>
<p>68、When in doubt, mumble.<br />
脑子不好使的话，你就嘟囔。<br />
不明白的话，哼哼试试。</p>
<p>69、I intend to live forever. So far, so good.<br />
我已决定长生不老，目前为止，感觉良好。</p>
<p>70、Hospitality: making your guests feel like they’re at home, even if you wish they were<br />
好客就是：让客人觉得他们像在他们家一样，尽管你真的希望他们滚回他们家。</p>
<p>71、If at first you don’t succeed, skydiving is not for you!<br />
跳伞是这样一种运动：不成功则成仁！</p>
<p>72、If you are supposed to learn from your mistakes, why do some people have more than one child.<br />
假设我们会吃一堑，长一智，为什么总有人生了一个还会生？</p>
<p>73、A TV can insult your intelligence, but nothing rubs it in like a computer.<br />
电视侮辱你的智商，电脑则是吐你槽的终极存在！</p>
<p>74、Knowledge is power, and power corrupts. So study hard and be evil.<br />
知识就是力量，力量会邪恶化。那么就好好学习当大魔王吧！</p>
<p>75、Money can’t buy happiness, but it sure makes misery easier to live with.<br />
钱买不来幸福，但有了它，痛苦的日子会好熬一点。</p>
<p>76、Always borrow money from a pessimist. He won’t expect it back.<br />
跟悲观主义者借钱吧！他反正不指望你还！！！</p>
<p>77、Worrying works! 90% of the things I worry about never happen.<br />
担忧真的好使！！老子担心的事儿90%都没发生！！</p>
<p>78、Virginity is like a soapbubble, one prick and it is gone.<br />
贞操如泡影，一戳无踪影。</p>
<p>79、Nostalgia isn’t what it used to be.<br />
这年头，连怀旧都不如从前够味儿了。</p>
<p>80、With sufficient thrust, pigs fly just fine.<br />
只要主义真，猪也成超人。<br />
信春哥 ，得永生</p>
<p>81、A bus is a vehicle that runs twice as fast when you are after it as when you are in it.<br />
公车总在被追赶的时候的速度要比你在里面时的速度快两倍。<br />
一旦你在公车后面追，它的速度就会变得比你在里面所感觉得快。</p>
<p>82、I should’ve known it wasn’t going to work out between my ex-wife and me. After all, I’m a Libra and she’s a bitch.<br />
我早就该知道我跟我EX没戏！归根结底，我是天枰她是JP！</p>
<p>83、Hallmark Card: “I’m so miserable without you, it’s almost like you’re still here.”<br />
豪马克卡上的话：没有你我痛苦万分，正如你就在此处。（没有女人冷冷清清，有了女人鸡犬不宁）</p>
<p>84、You’re never too old to learn something stupid.<br />
越活越2~ /活到老,2到老</p>
<p>85、A diplomat is someone who can tell you to go to hell in such a way that you will look forward to the trip.<br />
直译：外交家们说让你下地狱的时候，措辞也好像你正巴不得来这么趟旅行。</p>
<p>86、 I got in a fight one time with a really big guy, and he said, “I’m going to mop the floor with your face.” I said, “You’ll be sorry.” He said, “Oh, yeah? Why?” I said, “Well, you won’t be able to get into the corners very well.”<br />
我和个壮汉闹急了。 他：老子非得用你丫脸把地给擦了！！！ 我：你会后悔的！！ 他：噢？真哒？怎么讲？ 我：呃，边边角角的地方你擦不到！！！</p>
<p>87、Some people hear voices.. Some see invisible people.. Others have no imagination whatsoever.<br />
有些人吹牛说丫能通灵，有些人吹牛说丫有阴阳眼，其他人只是没有这种想象力而已</p>
<p>88、I like work. It fascinates me. I sit and look at it for hours.<br />
啊我好爱好爱工作啊~ 工作让我好着迷啊~我TMD死盯着它几个小时了啊！</p>
<p>89、We have enough gun control. What we need is idiot control.<br />
枪支管理不是问题，SB管理才是问题</p>
<p>90、Women may not hit harder, but they hit lower.<br />
女人或许击得并不重，但她们击得更低…..<br />
女人总是能击中男人的要害。</p>
<p>91、Just remember…if the world didn’t suck, we’d all fall off.<br />
直译：记着吧……世界要不恶心，我们早被吐掉了。<br />
别抱怨了，这个世界要是真和谐了，我们这种人就不应该存在~<br />
意译：你们TMD给我记住：没有和谐社会，你们早让美帝国主义给糟蹋了！</p>
<p>92、Jesus loves you, but everyone else thinks you’re an asshole.<br />
上帝蜀黍疼你，只是大家都觉得你2B而已</p>
<p>93、I used to be indecisive. Now I’m not sure.<br />
a. 过去老子左右为难。现在老子优柔寡断。<br />
b. 我曾是个怀疑论者，现在我很怀疑这一点。<br />
c. 过去我难以决断，现在我不大确信是否还是如此。</p>
<p>94、I don’t trust anything that bleeds for five days and doesn’t die.<br />
老子打死都不信流血5天还不挂的物种。/老子打死都不信娘们儿。</p>
<p>95、If you keep your feet firmly on the ground, you’ll have trouble putting on your pants.<br />
直译：如果你始终脚踏实地，那就别想穿裤子了。<br />
意译：人太老实没法活。</p>
<p>96、To be sure of hitting the target, shoot first and call whatever you hit the target.<br />
别人是指哪儿打哪儿，我是打哪儿指哪儿。</p>
<p>97、You are such a good friend that if we were on a sinking ship together and there was only one life jacket… I’d miss you heaps and think of you often.<br />
好吧，既然这艘船要沉了，救生衣又只有一件，我就勉为其难的虚伪一下，你对我来说实在是不能再好的朋友了…我一定会经常想念你滴~!!!</p>
<p>98、Going to church doesn’t make you a Christian any more than standing in a garage makes you a car.<br />
站在车库的你并不会变成一辆车是吧？所以站在教堂的你也不会变成基督徒。</p>
<p>99、Change is inevitable, except from a vending machine.<br />
世界总是在变，但我却怎么也便不出来。<br />
意译：人生何处不杯具，唯有面对饮水机。</p>
<p>100、Whoever coined the phrase “Quiet as a mouse” has never stepped on one.<br />
发明“鼠动无声”这词儿的哥们一定没踩上过一只。</p>
<p>/***************************************************************<br />
以上内容转载自http://www.wuliaoo.com/can-bao-ying-wen-fan-yi.html，版权属原始作者所有。<br />
****************************************************************/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yinzhili.com/2009/12/100-brilliant-translations.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>教程：如何使用CodeIgniter来更新Twitter</title>
		<link>http://www.yinzhili.com/2009/10/how-to-update-your-twitter-status-with-codeigniter.html</link>
		<comments>http://www.yinzhili.com/2009/10/how-to-update-your-twitter-status-with-codeigniter.html#comments</comments>
		<pubDate>Wed, 14 Oct 2009 01:33:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.yinzhili.com/?p=104</guid>
		<description><![CDATA[这是一篇原创译文，<strong>转载请注明出处</strong>。
原文作者Drazen Mokic，你可以在 <a href="http://net.tutsplus.com/tutorials/php/how-to-update-your-twitter-status-with-codeigniter/">这里</a> 看到原文。
在这个教程里面我们将使用CodeIgniter，通过Twitter API来更新我们的twitter状态。我建议大家一步一步的学习，而不要走马观花式的浏览教程。让我们开始深入学习吧！
教程细节
程序：C[......]<p class='read-more'><a href='http://www.yinzhili.com/2009/10/how-to-update-your-twitter-status-with-codeigniter.html'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">这是一篇原创译文，<strong>转载请注明出处</strong>。<br />
原文作者Drazen Mokic，你可以在 <a href="http://net.tutsplus.com/tutorials/php/how-to-update-your-twitter-status-with-codeigniter/">这里</a> 看到原文。</span></p>
<p>在这个教程里面我们将使用CodeIgniter，通过Twitter API来更新我们的twitter状态。我建议大家一步一步的学习，而不要走马观花式的浏览教程。让我们开始深入学习吧！</p>
<p>教程细节<br />
程序：CodeIgniter框架<br />
版本：1.7.1<br />
难度：高级<br />
预计完成时间：30分钟</p>
<h3>1.配置CodeIgniter</h3>
<p>首先我们需要对CI的默认配置进行修改。打开 <span style="color: #ff0000;">system/application/config/autoload.php</span> 文件，找到下面这行</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'libraries'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>修改为</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoload</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'libraries'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>这样就可以自动加载数据库了。接下来，打开 <span style="color: #0000ff;">database.php </span>并修改其中的数据库连接设置-你的数据库名、用户名以及密码。我们使用的名称是 <span style="color: #0000ff;">ci_twitter_api</span>。<br />
现在打开 <span style="color: #0000ff;">config.php</span>，并修改 <span style="color: #0000ff;">base_url</span> 为你的CI目录路径。我使用的目录叫做 <span style="color: #0000ff;">twitter_api</span>，我的 <span style="color: #0000ff;">system</span>目录就保存在那个位置，因此我的 <span style="color: #0000ff;">base_url</span> 会是</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_url'</span><span style="color: #009900;">&#93;</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://localhost/ci/twitter_api&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>2.填充数据库</h3>
<p>因为我们将要用到数据库，所以我们需要填充一些数据。打开 phpMyAdmin 或者其它你喜欢的数据库管理工具，创建一个新的数据库，命名为 <span style="color: #0000ff;">ci_twitter_api</span>。现在我们将要使用下面的SQL查询语句来创建一个表，但请注意，使用你自己的twitter用户名和密码。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`accounts`</span> <span style="color: #66cc66;">&#40;</span>
     <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
     <span style="color: #ff0000;">`username`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">120</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
     <span style="color: #ff0000;">`password`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
     <span style="color: #ff0000;">`active`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
     <span style="color: #ff0000;">`last_message`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">140</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
     <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM  <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>latin1 <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">3</span> ;
&nbsp;
   <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`accounts`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`username`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`password`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`active`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`last_message`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span>
   <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'&lt;strong&gt;YOUR USERNAME&lt;/strong&gt;'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'&lt;strong&gt;YOUR PASSWORD&lt;/strong&gt;'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'No message sent.'</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<div id="attachment_107" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-107" title="图1" src="http://www.yinzhili.com/wp-content/uploads/2009/10/img11.jpg" alt="图1" width="500" height="300" /><p class="wp-caption-text">图1</p></div>
<p>单击右边的 <span style="color: #0000ff;"><strong>OK </strong></span>按钮，查询就会被提交。现在你的<span style="color: #0000ff;">accounts</span>表的结构应该和下图是类似的:</p>
<div id="attachment_109" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-109" title="图2" src="http://www.yinzhili.com/wp-content/uploads/2009/10/img2.jpg" alt="图2" width="500" height="81" /><p class="wp-caption-text">图2</p></div>
<h3>3.构建模型</h3>
<p>转到 <span style="color: #ff0000;">system/application/models</span> 下面，新建一个文件并命名为 <span style="color: #0000ff;">twitter_model.php</span>。<br />
首先，我们在顶部声明两个全局变量。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$accounts_table</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'accounts'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$update_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://twitter.com/statuses/update.xml'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>因此，<span style="color: #0000ff;">$accounts_table</span> 对应的是我们之前所创建的表，<span style="color: #0000ff;">$update_url</span> 则是我们用来更新状态的URL。如果Twitter更改了它的更新URL，你只需要修改一次就可以了，不必每次都修改。<br />
现在我们将要创建第一个方法，作用是返回数据库中存储的活跃用户帐户，依据是active字段及其值1。我添加了这一项是因为可能有些人拥有多个twitter账户。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Twitter_model <span style="color: #000000; font-weight: bold;">extends</span> Model <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// get the active twitter account from the database, by row active = 1</span>
    <span style="color: #000000; font-weight: bold;">function</span> getActiveAccount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_where</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">accounts_table</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'active'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>我们简单的使用 ActiveRecord 来检索活跃的账户并返回受影响的行。<br />
下一步，我们将要构建主要方法，也就是 <span style="color: #0000ff;">update </span>方法。它将要用到我们的用户名、密码以及我们想要在Twitter上更新的消息。除此之外，它还将对Twitter所返回的 HTTP_CODE 进行解析，以便告诉我们更新是否成功。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// update twitter status and last message on success</span>
<span style="color: #000000; font-weight: bold;">function</span> update_status<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">'status='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERPWD<span style="color: #339933;">,</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$httpcode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_getinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLINFO_HTTP_CODE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// if we were successfull we need to update our last_message</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpcode</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'200'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'active'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">accounts_table</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'last_message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>乍一看去这段代码有点复杂，但并不是很难理解的。最重要的一点是，我们使用了 cURL 和Twitter进行通信。cURL是一个非常优秀的库，允许我们通过它来发送和接收来自Twitter的HTTP POST数据。<br />
那么，curl_init 初始化一个cURL会话并将URL作为参数接受-在我们这个案例中就是Twitter API所提供的更新URL。<br />
我们通过 curl_setopt 设置了一些选项，这些对于 cURL传输来说是必不可少的。</p>
<ul><strong><span style="color: #0000ff;">CURLOPT_POST</span>:</strong> 此项设置为&#8217;1&#8242;，表示我们将使用 HTTP POST，这与HTML表单中是一样的。<br />
<strong><span style="color: #0000ff;">CURLOPT_POSTFIELDS</span>:</strong> 此项接收的是我们想要发送的 POST 数据。在本案例中是 &#8217;status=&#8217; 和我们要发送的消息。我们需要对消息进行 urlencode ，以便使用 &#8216;%&amp;/&#8221; 这类的特殊字符。<br />
<strong><span style="color: #0000ff;">CURLOPT_RETURNTRANSFER</span>: </strong>将此项设置为&#8217;1&#8242;是非常重要的，因为它将把传输作为字符串返回。这一字符串将告诉我们更新是否成功。<br />
<strong><span style="color: #0000ff;">CURLOPT_USERPWD</span>: </strong>此项的作用是身份验证。它只是以 <em><span style="color: #0000ff;">用户名:密码</span></em> 这种格式包含我们的twitter帐户信息。</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$httpcode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_getinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLINFO_HTTP_CODE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// if we were successfull we need to update our last_message</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpcode</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'200'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'active'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">accounts_table</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'last_message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>在这一部分我们通过 curl_exec() 执行传输并且使用 <span style="color: #0000ff;">curl_getinfo(CURLINFO_HTTP_CODE) </span>来检索返回的HTTP_CODE。这里的HTTP_CODE将告诉我们更新是否成功。代码&#8217;200&#8242;表示更新成功。你可以在 <a href="http://apiwiki.twitter.com/HTTP-Response-Codes-and-Errors">这里</a> 查看到一份完整的HTTP状态代码列表。<br />
如果我们收到了Twitter所返回的&#8217;200&#8242;，我们将向数据库发出一条查询语句，用来更新last_message字段，最后我们返回TRUE。如果Twitter没有返回200，我们简单的返回FALSE。<br />
为了完成我们的 twitter_model，我们还将创建最后一个方法，作用是获取我们最后发送的信息。我们之所以需要这个方法是因为我们要在视图中显示最近发送的信息。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// get the last_message, by row active = 1</span>
<span style="color: #000000; font-weight: bold;">function</span> getLastMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'last_message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$last_message</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_where</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">accounts_table</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'active'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">last_message</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$last_message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>这个方法很简单。它从我们的活跃帐户所对应的last_message字段检索信息，并经过 htmlspecialchars 转换成HTML实体返回。我们的 twitter_model.php 看起来像这样:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">class</span> Twitter_model <span style="color: #000000; font-weight: bold;">extends</span> Model <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$accounts_table</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'accounts'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$update_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://twitter.com/statuses/update.xml'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// get the active twitter account from the database, by row active = 1</span>
	<span style="color: #000000; font-weight: bold;">function</span> getActiveAccount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_where</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">accounts_table</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'active'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// update twitter status and last message on success</span>
	<span style="color: #000000; font-weight: bold;">function</span> update_status<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">'status='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERPWD<span style="color: #339933;">,</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$httpcode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_getinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLINFO_HTTP_CODE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// if we were successfull we need to update our last_message</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpcode</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'200'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'active'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">accounts_table</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'last_message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// get the last_message, by row active = 1</span>
	<span style="color: #000000; font-weight: bold;">function</span> getLastMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'last_message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$last_message</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_where</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">accounts_table</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'active'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">row</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">last_message</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$last_message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>4.构建控制器<br />
现在转到 <span style="color: #ff0000;">system/application/controllers</span>，新建一个文件，命名为 twitter.php。让我们添加几行：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Twitter <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> Twitter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	parent<span style="color: #339933;">::</span><span style="color: #004000;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>这是一个简单的CI构造函数，加载我们的 twitter_model。因此整个控制器都是可用的。下面是 index() 方法。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'heading'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Hi, send a tweet!'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'last_message'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLastMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'active_user'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActiveAccount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'footer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>我们将文本、最近的消息、活跃帐户的用户名等信息传递给 $data 数组。获取最近的消息以及活跃的用户名变得轻而易举，这应该归功于我们的 twitter_model。最后我们加载一些视图(编写完控制器后就会创建它们)。让我们来构建 update 方法吧。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// updating our status on twitter ( new message )</span>
<span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form_validation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_error_delimiters</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;div class=&quot;error&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'trim|required|min_length[5]|max_length[140]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">index</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// get useraccount data</span>
			<span style="color: #000088;">$account</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActiveAccount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$account</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$account</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// send a tweet</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update_status</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'There was an error while updating your status'</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'footer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>这可能又会使你感到迷惑，但我们还是逐步的完成它。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form_validation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_error_delimiters</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
&lt;div class=&quot;error&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/div&gt;
'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'trim|required|min_length[5]|max_length[140]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">index</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>我们通过 <span style="color: #0000ff;">$this->input->post(&#8217;submit&#8217;)  </span>检查表单(稍后我们会在主要的视图文件中创建它)是否已被提交。然后，我们加载表单验证类，因为我们希望使用某些输入规则，比如最短5个字符、最多140个字符。此外我们还使用 trim 来过滤掉空格，并将此字段设置为 required(必需)，因为我们不需要空的消息。set_rules函数的第一个参数是表单字段的名称，在本案例中是 message (稍后我们会在视图中创建它)，第二个参数则是此表单字段的“人性化”的名称，它将被插入到错误信息中(将在视图文件中完成)。<br />
我们调用 <span style="color: #0000ff;">$this->form_validation->run()</span> ，此方法返回 TRUE 或者 FALSE。如果我们所设置的某条规则被破坏，它将返回 FALSE 并且调用我们的 index() 方法。而 index() 方法所调用的视图中就会显示错误信息。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">else</span>
   <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
       <span style="color: #666666; font-style: italic;">// get useraccount data</span>
       <span style="color: #000088;">$account</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActiveAccount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$account</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$account</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span><span style="color: #339933;">;</span>  
&nbsp;
       <span style="color: #666666; font-style: italic;">// send a tweet</span>
       <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update_status</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
           redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>  
&nbsp;
       <span style="color: #b1b100;">else</span>
       <span style="color: #009900;">&#123;</span>
           <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'There was an error while updating your status'</span><span style="color: #339933;">;</span>  
&nbsp;
           <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'footer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>再次感谢我们的 twitter_model，检索当前的用户名和密码变得轻而易举。当然我们也可以使用 <span style="color: #0000ff;">$username = $this->twitter_model->getActiveAccount()->username</span> ，但我觉得对这段教程来说这就更好理解一些。<br />
通过 $this->twitter_model->update_status() 我们调用那个与Twitter进行“通话”的方法。它把我们的用户名、密码以及我们要发送的消息告诉Twitter。如果状态更新成功，我们就会调用URL辅助函数中的 redirect() 进行重定向。<br />
如果出了错，我们设置一条错误消息并加载几个视图文件(下一步会创建它们)。现在控制器看上去是这样的：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Twitter <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> Twitter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>  
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'heading'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Hi, send a tweet!'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'last_message'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLastMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'active_user'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActiveAccount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">;</span>  
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'footer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>  
&nbsp;
<span style="color: #666666; font-style: italic;">// updating our status on twitter ( new message )</span>
<span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form_validation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_error_delimiters</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
&lt;div class=&quot;error&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/div&gt;
'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'trim|required|min_length[5]|max_length[140]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">index</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>  
&nbsp;
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
            <span style="color: #666666; font-style: italic;">// get useraccount data</span>
            <span style="color: #000088;">$account</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActiveAccount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$account</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$account</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span><span style="color: #339933;">;</span>  
&nbsp;
            <span style="color: #666666; font-style: italic;">// send a tweet</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">twitter_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update_status</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>  
&nbsp;
            <span style="color: #b1b100;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'There was an error while updating your status'</span><span style="color: #339933;">;</span>  
&nbsp;
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'footer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>  
&nbsp;
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
        redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>5.创建视图<br />
现在我们就要创建视图文件了。转到 <span style="color: #ff0000;">system/application/views </span>下面，创建如下几个文件：<br />
<span style="color: #0000ff;">header.php<br />
footer.php<br />
index.php<br />
error.php</span></p>
<p>header.php将包含基本的HTML元信息、我们的CSS链接以及主要的div(如#wrapper 和 #main)开启标签。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt; !DOCTYPE html&gt;  
&lt;html&gt;  
&lt;head&gt;  
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;  
&lt;link media=&quot;screen&quot; rel=&quot;Stylesheet&quot; type=&quot;text/css&quot; href=&quot;&lt;?php echo base_url(); ?&gt;css/style.css&quot; /&gt;  
&lt;title&gt;Using the Twitter API with CodeIgniter&lt;/title&gt;  
&lt;/link&gt;&lt;/head&gt;  
&nbsp;
&lt;body&gt;  
&nbsp;
&lt;div id=&quot;wrapper&quot;&gt;  
&nbsp;
&lt;div id=&quot;main&quot;&gt;</pre></td></tr></table></div>

<p>我们使用 base_url() 来引用我们的CSS文件(下一步会创建它)。<br />
footer.php只是包含了我们的关闭标签。</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">  &lt;/div&gt;&lt;!--end main--&gt;  
&nbsp;
    &lt;/div&gt;&lt;!--end wrapper--&gt;&lt;/body&gt;&lt;/html&gt;</pre></div></div>

<p>index.php才是最重要的部分。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$heading</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
    <span style="color: #009900;">&#40;</span> account<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">echo</span> anchor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://twitter.com/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$active_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$active_user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;/</span>h3<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">echo</span> form_error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>  
&nbsp;
   <span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">echo</span> form_open<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter/update'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'update_form'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   <span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">echo</span> form_input<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'maxlength'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'140'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   <span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">echo</span> form_submit<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'submit'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'update'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   <span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">echo</span> form_close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;last_message&quot;</span><span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span>fieldset<span style="color: #339933;">&gt;</span>
           <span style="color: #339933;">&lt;</span>legend<span style="color: #339933;">&gt;</span>Last sent by <span style="color: #339933;">&lt;</span>strong<span style="color: #339933;">&gt;&lt;</span> ?php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$active_user</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>strong<span style="color: #339933;">&gt;&lt;/</span>legend<span style="color: #339933;">&gt;</span>  
&nbsp;
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$last_message</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
       <span style="color: #339933;">&lt;/</span>fieldset<span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;!--</span><span style="color: #990000;">end</span> last_message<span style="color: #339933;">--&gt;</span></pre></td></tr></table></div>

<p>这里用到的所有变量都是通过我们的控制器中的 index() 方法传递的。除此之外，我们还使用了表单辅助函数来创建一个简单的HTML表单。记住，我告诉过你，这里是进行错误处理的地方；form_error(&#8216;message&#8217;) 就是完成这一工作的魔法师。<br />
在表单下面，显示的是当前活跃用户所发送的最后一则消息。<br />
最后，error.php作为一个自定义的错误文件，万一出现更新不成功的情况就可以用得上。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;&lt;</span> ?php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$error</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>h3<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">echo</span> anchor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitter'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Go back and try again'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>6.添加一些CSS<br />
为了使页面更加美观，我们将添加一些CSS。转到 system/ 下面并创建 css目录。在那个目录下创建一个 style.css 文件，然后输入如下的代码。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Reset CSS */</span>  
&nbsp;
html<span style="color: #00AA00;">,</span> body<span style="color: #00AA00;">,</span> div<span style="color: #00AA00;">,</span> span<span style="color: #00AA00;">,</span> object<span style="color: #00AA00;">,</span> h1<span style="color: #00AA00;">,</span> h2<span style="color: #00AA00;">,</span> h3<span style="color: #00AA00;">,</span> h4<span style="color: #00AA00;">,</span> h5<span style="color: #00AA00;">,</span> h6<span style="color: #00AA00;">,</span> p<span style="color: #00AA00;">,</span> blockquote<span style="color: #00AA00;">,</span> pre<span style="color: #00AA00;">,</span>
a<span style="color: #00AA00;">,</span> address<span style="color: #00AA00;">,</span> code<span style="color: #00AA00;">,</span> img<span style="color: #00AA00;">,</span>
small<span style="color: #00AA00;">,</span> strong<span style="color: #00AA00;">,</span> dl<span style="color: #00AA00;">,</span> dt<span style="color: #00AA00;">,</span> dd<span style="color: #00AA00;">,</span> ol<span style="color: #00AA00;">,</span> ul<span style="color: #00AA00;">,</span> li<span style="color: #00AA00;">,</span>
fieldset<span style="color: #00AA00;">,</span> form<span style="color: #00AA00;">,</span> label <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> baselinebaseline<span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
body <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1.5</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Arial</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
ol<span style="color: #00AA00;">,</span> ul<span style="color: #00AA00;">,</span> li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">list-style-type</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #6666ff;">.clear</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #808080; font-style: italic;">/* DEFAULTS */</span>  
&nbsp;
h3 <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#35CCFF</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #808080; font-style: italic;">/* CUSTOM */</span>  
&nbsp;
<span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">900px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #808080; font-style: italic;">/* main */</span>  
&nbsp;
<span style="color: #cc00cc;">#main</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #cc00cc;">#main</span> h3 span <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#cccccc</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #cc00cc;">#main</span> h3 a <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#cccccc</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #808080; font-style: italic;">/* form */</span>  
&nbsp;
<span style="color: #cc00cc;">#update_form</span> input <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">888px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#d3d3d3</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #cc00cc;">#update_form</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000000</span><span style="color: #00AA00;">;;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #993333;">white</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
div<span style="color: #6666ff;">.error</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FB8A8A</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#FF3B3B</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span> <span style="color: #933;">10px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #808080; font-style: italic;">/* last message */</span>  
&nbsp;
<span style="color: #cc00cc;">#last_message</span> fieldset <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">dashed</span> <span style="color: #cc00cc;">#d3d3d3</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #cc00cc;">#last_message</span> fieldset p <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">18px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>  
&nbsp;
<span style="color: #cc00cc;">#last_message</span> legend span <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>我使用了 Eric Meyers 的CSS重置方法，这样可以消除不同浏览器之间的差异。你的应用程序看上去应该像下图这样。</p>
<div id="attachment_110" class="wp-caption alignnone" style="width: 610px"><img class="size-full wp-image-110" title="图3" src="http://www.yinzhili.com/wp-content/uploads/2009/10/img3.jpg" alt="图3" width="600" height="300" /><p class="wp-caption-text">图3</p></div>
<h1><strong>大结局</strong></h1>
<p>现在让我们来测试一下新编写的应用程序。我们将输入一条信息并单击 update 按钮！</p>
<div id="attachment_111" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-111" title="图4" src="http://www.yinzhili.com/wp-content/uploads/2009/10/img4.jpg" alt="图4" width="500" height="300" /><p class="wp-caption-text">图4</p></div>
<p>更新完成后就会显示:</p>
<div id="attachment_113" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-113" title="图5" src="http://www.yinzhili.com/wp-content/uploads/2009/10/img51.jpg" alt="图5" width="500" height="300" /><p class="wp-caption-text">图5</p></div>
<p>让我们看看Twitter:)</p>
<div id="attachment_114" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-114" title="图6" src="http://www.yinzhili.com/wp-content/uploads/2009/10/img6.jpg" alt="图6" width="500" height="300" /><p class="wp-caption-text">图6</p></div>
<p>如果我们试图发送一则空消息，破坏了表单验证规则：</p>
<div id="attachment_115" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-115" title="图7" src="http://www.yinzhili.com/wp-content/uploads/2009/10/img7.jpg" alt="图7" width="500" height="300" /><p class="wp-caption-text">图7</p></div>
<h1><strong>结论</strong></h1>
<p>我真心希望这对你学习CodeIgniter和如何使用优秀的Twitter API有所帮助！你遇到难题了么? 如果有，请告诉我们！</p>
<p><span style="color:#ff0000;"><br />
<h1><strong>译者后记</strong></h1>
<p>由于众所周知的某原因，如果不使用代理，我们无法在国内访问到Twitter主站，甚至包括其API。这样的话如果使用Twitter官方的API就会导致更新失败。没有关系，我们可以使用第三方的API来完成这个工作。<br />
打开 twitter_model.php ，找到这一行:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$update_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://twitter.com/statuses/update.xml'</span><span style="color: #339933;">;</span></pre></div></div>

<p>修改为</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$update_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://nest.onedd.net/api/statuses/update.xml'</span><span style="color: #339933;">;</span></pre></div></div>

<p>这样就可以了。下面是我的测试结果:<br />
<div id="attachment_133" class="wp-caption alignnone" style="width: 537px"><img src="http://www.yinzhili.com/wp-content/uploads/2009/10/11.PNG" alt="我的测试结果1" title="我的测试结果1" width="527" height="213" class="size-full wp-image-133" /><p class="wp-caption-text">我的测试结果1</p></div></p>
<p>下面是Twitter主站上看到的结果:<br />
<div id="attachment_134" class="wp-caption alignnone" style="width: 569px"><img src="http://www.yinzhili.com/wp-content/uploads/2009/10/2.PNG" alt="Twitter主站上的测试结果" title="Twitter主站上的测试结果" width="559" height="307" class="size-full wp-image-134" /><p class="wp-caption-text">Twitter主站上的测试结果</p></div> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yinzhili.com/2009/10/how-to-update-your-twitter-status-with-codeigniter.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter 中文用户指南 版本 1.7.2 CHM版发布(支持索引和搜索)</title>
		<link>http://www.yinzhili.com/2009/10/codeigniter-userguide-1-7-2-cn-chm.html</link>
		<comments>http://www.yinzhili.com/2009/10/codeigniter-userguide-1-7-2-cn-chm.html#comments</comments>
		<pubDate>Mon, 12 Oct 2009 03:15:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CHM]]></category>

		<guid isPermaLink="false">http://www.yinzhili.com/?p=99</guid>
		<description><![CDATA[上个月制作了CodeIgniter 1.7.2中文手册的CHM版，但由于制作工具的原因，生成的索引和搜索结果出现了乱码，非常无奈，只好取消了CHM文件的索引和搜索功能。
最近经过仔细研究后才发现，原始的HTML文件使用的是UTF-8编码，这是造成乱码的根本原因所在。于是用编码转换工具将所有HTML文[......]<p class='read-more'><a href='http://www.yinzhili.com/2009/10/codeigniter-userguide-1-7-2-cn-chm.html'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>上个月制作了CodeIgniter 1.7.2中文手册的CHM版，但由于制作工具的原因，生成的索引和搜索结果出现了乱码，非常无奈，只好取消了CHM文件的索引和搜索功能。<br />
最近经过仔细研究后才发现，原始的HTML文件使用的是UTF-8编码，这是造成乱码的根本原因所在。于是用编码转换工具将所有HTML文件的编码转换为GB2312，再用QuickCHM编译生成CHM文件，完美地解决了搜索和索引的乱码问题。<br />
<div id="attachment_100" class="wp-caption alignnone" style="width: 310px"><img src="http://www.yinzhili.com/wp-content/uploads/2009/10/1-300x198.PNG" alt="CHM版截图" title="截图" width="300" height="198" class="size-medium wp-image-100" /><p class="wp-caption-text">CHM版截图</p></div></p>
<p><a href="http://www.yinzhili.com/wp-content/uploads/2009/10/CodeIgniter_UserGuide_cn.zip"><font -size="5">单击此处立即下载</font></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yinzhili.com/2009/10/codeigniter-userguide-1-7-2-cn-chm.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpMyAdmin升级到3.2.x版遇到的常见问题</title>
		<link>http://www.yinzhili.com/2009/09/problems-you-will-encounter-when-using-phpmyadmin3.html</link>
		<comments>http://www.yinzhili.com/2009/09/problems-you-will-encounter-when-using-phpmyadmin3.html#comments</comments>
		<pubDate>Wed, 30 Sep 2009 02:32:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[MYSQL]]></category>
		<category><![CDATA[phpMyAdmin]]></category>

		<guid isPermaLink="false">http://www.yinzhili.com/?p=93</guid>
		<description><![CDATA[phpMyAdmin是一个用PHP编写的基于Web的MySQL管理工具。从事过PHP+MySQL开发的朋友肯定接触过它，非常方便。最近把电脑上的phpMyAdmin升级到了3.2.2版，遇到了一些问题，在此总结一下。
1. “空密码登录被禁止” &#160;问题
很多时候我们在本机测试时会将root[......]<p class='read-more'><a href='http://www.yinzhili.com/2009/09/problems-you-will-encounter-when-using-phpmyadmin3.html'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>phpMyAdmin是一个用PHP编写的基于Web的MySQL管理工具。从事过PHP+MySQL开发的朋友肯定接触过它，非常方便。最近把电脑上的phpMyAdmin升级到了3.2.2版，遇到了一些问题，在此总结一下。</p>
<p>1. <font color="Red">“空密码登录被禁止”</font> &nbsp;问题<br />
很多时候我们在本机测试时会将root用户密码设置为空。但升级到phpMyAdmin 3.2.2版的时候，会遇到无法以空密码登录root用户的情况。怎么解决呢? 请参照如下步骤：<br />
(1) 找到你的phpMyAdmin程序所在的目录，这个根据你个人的情况有所不同。<br />
(2) 打开 phpMyAdmin\libraries\ 路径下的 <strong>config.default.php</strong> 这个文件，找到下面这行</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$cfg</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Servers'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'AllowNoPassword'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span></pre></div></div>

<p>将其修改为</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$cfg</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Servers'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'AllowNoPassword'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span></pre></div></div>

<p>(3) 重新访问你的phpMyAdmin，你会发现空密码的root用户也可以登录了。</p>
<p>2. <font color="Red">“配置文件现在需要一个短语密码”</font>&nbsp;问题<br />
在登录进去之后可能会看到<font color="Red">“配置文件现在需要一个短语密码”</font>这条警告信息。这是因为你没有设置一个用来给Cookie加密的密钥。解决方法还是首先打开上文所说的 config.default.php 文件，并找到下面这行</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$cfg</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'blowfish_secret'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></pre></div></div>

<p>将其修改为</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$cfg</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'blowfish_secret'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'你的密钥'</span><span style="color: #339933;">;</span></pre></div></div>

<p>说明: 这里的“你的密钥”是你所设置的密钥字符串，可以随意设置。<br />
修改保存之后，重新登录phpMyAdmin就可以了。</p>
<p>3. <font color="Red">“无法载入mcrypt扩展”</font>&nbsp;问题<br />
这个问题与phpMyAdmin没有多少关系，是因为你的 PHP 运行环境没有开启mcrypt扩展。以Windows下为例，首先你要确保PHP目录的ext子目录下有 php_mcrypt.dll 这个文件，没有的话去网上下载一个。然后打开你的 php.ini 文件，找到下面这行</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">;</span>extension<span style="color: #339933;">=</span>php_mcrypt<span style="color: #339933;">.</span>dll</pre></div></div>

<p>去掉这行行首的分号，保存，然后重启Apache就可以开启mcrypt支持了。这个时候重新登陆phpMyAdmin，此问题就已经解决。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yinzhili.com/2009/09/problems-you-will-encounter-when-using-phpmyadmin3.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>升级到Windows 7 Ultimate</title>
		<link>http://www.yinzhili.com/2009/09/upgrade-to-windows-7-ultimate.html</link>
		<comments>http://www.yinzhili.com/2009/09/upgrade-to-windows-7-ultimate.html#comments</comments>
		<pubDate>Sun, 20 Sep 2009 02:59:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[杂谈]]></category>

		<guid isPermaLink="false">http://www.yinzhili.com/?p=89</guid>
		<description><![CDATA[昨天闲着无聊，下载了Windows 7 Ultimate的镜像文件，原本是打算今后买了新电脑再安装的。但是突然想起来我现在这台式机也曾安装过Win7的测试版，感觉还行，就是驱动不好找，运行倒是很流畅。我就想试试看正式版的Win7是不是会自带大部分的驱动，对旧硬件的识别是否有所改进，但结果是很伤心的。[......]<p class='read-more'><a href='http://www.yinzhili.com/2009/09/upgrade-to-windows-7-ultimate.html'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>昨天闲着无聊，下载了Windows 7 Ultimate的镜像文件，原本是打算今后买了新电脑再安装的。但是突然想起来我现在这台式机也曾安装过Win7的测试版，感觉还行，就是驱动不好找，运行倒是很流畅。我就想试试看正式版的Win7是不是会自带大部分的驱动，对旧硬件的识别是否有所改进，但结果是很伤心的。别的设备很容易被识别，而且Win7自带的那些驱动似乎也可以使它们正常运转，但我的集成显卡就悲剧了，根本就无法被识别出来，最多只能设置到1024&#215;768的分辨率。说明一下，我这机器比较老，用的是Ati RC410芯片组，在当年这集成显卡也还算不错，想不到现在居然面临无驱动可用的地步，甚至用自动更新也不行。<br />
<div id="attachment_90" class="wp-caption alignnone" style="width: 469px"><img class="size-full wp-image-90" title="悲剧啊" src="http://www.yinzhili.com/wp-content/uploads/2009/09/1228571988_6627b11c.jpg" alt="悲剧啊" width="459" height="346" /><p class="wp-caption-text">悲剧啊</p></div><br />
最后，我找到了一份Vista版的驱动，发现居然能用，还能开启Aero效果，真是神了。<br />
<div id="attachment_91" class="wp-caption alignnone" style="width: 727px"><img src="http://www.yinzhili.com/wp-content/uploads/2009/09/win7.png" alt="win7" title="win7" width="717" height="732" class="size-full wp-image-91" /><p class="wp-caption-text">win7</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yinzhili.com/2009/09/upgrade-to-windows-7-ultimate.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter发布1.7.2版</title>
		<link>http://www.yinzhili.com/2009/09/codeigniter-1-7-2-released.html</link>
		<comments>http://www.yinzhili.com/2009/09/codeigniter-1-7-2-released.html#comments</comments>
		<pubDate>Sat, 12 Sep 2009 14:58:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://www.yinzhili.com/?p=83</guid>
		<description><![CDATA[CodeIgniter 发布 1.7.2 版
EllisLab 发布了 CodeIgniter 1.7.2。有什么新内容？主要的更改如下：
<strong>兼容 PHP 5.3.0。</strong>
新增购物车类库。
改善表单辅助函数。
在公共函数中新增 is_php()，让 PHP 版本比较更方便。
修改 show_error([......]<p class='read-more'><a href='http://www.yinzhili.com/2009/09/codeigniter-1-7-2-released.html'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>CodeIgniter 发布 1.7.2 版</p>
<p>EllisLab 发布了 CodeIgniter 1.7.2。有什么新内容？主要的更改如下：</p>
<p><strong><span style="color: #ff0000;">兼容 PHP 5.3.0。</span></strong><br />
新增购物车类库。<br />
改善表单辅助函数。<br />
在公共函数中新增 is_php()，让 PHP 版本比较更方便。<br />
修改 show_error() 以便发送 HTTP 服务器响应码，并且所有内部错误提示都会发送合适的状态码。<br />
修复了很多 BUG。<br />
1.7.2 版已经在 subversion 中存在了很长一段时间了，并且已经于 7 月下旬兼容于 PHP 5.3.0，不过可以理解的是许多用户并没有使用那个开发中的版本。虽然我也希望能有时间为这个版本多增加一些“大改动”的项目，并把版本号变为 1.8，但时间不等人。我们的许多用户都在 Mac 上开发，但 OS X“雪豹”中的 PHP 是 5.3.0，所以与其让用户继续等待不如先推出这个稳定版&#8211;毕竟已经 7 个月没有更新了。虽然如此，也还是有一些惊喜和可喜的变化。敬请享用！</p>
<p>以上内容转自<a href="http://codeigniter.org.cn/blog">http://codeigniter.org.cn/blog</a>。</p>
<p><strong>详细的Change Log:</strong></p>
<p>版本 1.7.2<br />
发布日期：2009年9月11日<br />
SVN 版本: 1737</p>
<p>Libraries<br />
Added a new Cart Class.<br />
Added the ability to pass $config['file_name'] for the File Uploading Class and rename the uploaded file.<br />
Changed order of listed user-agents so Safari would more accurately report itself. (#6844)<br />
Database<br />
Switched from using gettype() in escape() to is_* methods, since future PHP versions might change its output.<br />
Updated all database drivers to handle arrays in escape_str()<br />
Added escape_like_str() method for escaping strings to be used in LIKE conditions<br />
Updated Active Record to utilize the new LIKE escaping mechanism.<br />
Added reconnect() method to DB drivers to try to keep alive / reestablish a connection after a long idle.<br />
Modified MSSQL driver to use mssql_get_last_message() for error messages.<br />
Helpers<br />
Added form_multiselect() to the Form helper.<br />
Modified form_hidden() in the Form helper to accept multi-dimensional arrays.<br />
Modified form_prep() in the Form helper to keep track of prepped fields to avoid multiple prep/mutation from subsequent calls which can occur when using Form Validation and form helper functions to output form fields.<br />
Modified directory_map() in the Directory helper to allow the inclusion of hidden files, and to return FALSE on failure to read directory.<br />
Modified the Smiley helper to work with multiple fields and insert the smiley at the last known cursor position.<br />
General<br />
Compatible with PHP 5.3.0<br />
Modified show_error() to allow sending of HTTP server response codes.<br />
Modified show_404() to send 404 status code, removing non-CGI compatible header() statement from error_404.php template.<br />
Added set_status_header() to the Common functions to allow use when the Output class is unavailable. Common functions to facilitate PHP version comparisons.<br />
Added is_php() to<br />
Added 2 CodeIgniter &#8220;cheatsheets&#8221; (thanks to DesignFellow.com for this contribution).<br />
1.7.2 修复的 BUG<br />
Fixed assorted user guide typos or examples (#6743, #7214, #7516, #7287, #7852, #8224, #8324, #8349).<br />
Fixed a bug in the Form Validation library where multiple callbacks weren&#8217;t working (#6110)<br />
doctype helper default value was missing a &#8220;1&#8243;.<br />
Fixed a bug in the language class when outputting an error for an unfound file.<br />
Fixed a bug in the Calendar library where the shortname was output for &#8220;May&#8221;.<br />
Fixed a bug with ORIG_PATH_INFO that was allowing URIs of just a slash through.<br />
Fixed a fatal error in the Oracle and ODBC drivers (#6752)<br />
Fixed a bug where xml_from_result() was checking for a nonexistent method.<br />
Fixed a bug where Database Forge&#8217;s add_column and modify_column were not looping through when sent multiple fields.<br />
Fixed a bug where the File Helper was using &#8216;/&#8217; instead of the DIRECTORY_SEPARATOR constant.<br />
Fixed a bug to prevent PHP errors when attempting to use sendmail on servers that have manually disabled the PHP popen() function.<br />
Fixed a bug that would cause PHP errors in XML-RPC data if the PHP data type did not match the specified XML-RPC type.<br />
Fixed a bug in the XML-RPC class with parsing dateTime.iso8601 data types.<br />
Fixed a case sensitive string replacement in xss_clean()<br />
Fixed a bug in form_textarea() where form data was not prepped correctly.<br />
Fixed a bug in form_prep() causing it to not preserve entities in the user&#8217;s original input when called back into a form element<br />
Fixed a bug in _protect_identifiers() where the swap prefix ($swap_pre) was not being observed.<br />
Fixed a bug where the 400 status header sent with the &#8216;disallowed URI characters&#8217; was not compatible with CGI environments.<br />
Fixed a bug in the typography class where heading tags could have paragraph tags inserted when using auto_typography().<br />
<strong>下载1.7.2版:<br />
</strong><a href="http://codeigniter.org.cn/downloads">http://codeigniter.org.cn/downloads</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yinzhili.com/2009/09/codeigniter-1-7-2-released.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Noel Gallagher宣布退出Oasis</title>
		<link>http://www.yinzhili.com/2009/08/noel-gallagher-quits-oasis.html</link>
		<comments>http://www.yinzhili.com/2009/08/noel-gallagher-quits-oasis.html#comments</comments>
		<pubDate>Sat, 29 Aug 2009 16:30:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[音乐&电影]]></category>
		<category><![CDATA[Oasis]]></category>

		<guid isPermaLink="false">http://www.yinzhili.com/?p=78</guid>
		<description><![CDATA[今天中午看到一则重大新闻：英国Oasis乐队的吉他手、主要的歌曲创作者以及第二主唱，同时也是乐队的核心，主唱的哥哥，Noel Gallagher (诺埃尔·加勒格)在乐队的官网发布了这样一则声明:
It&#8217;s with some sadness and great relief to te[......]<p class='read-more'><a href='http://www.yinzhili.com/2009/08/noel-gallagher-quits-oasis.html'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>今天中午看到一则重大新闻：英国Oasis乐队的吉他手、主要的歌曲创作者以及第二主唱，同时也是乐队的核心，主唱的哥哥，Noel Gallagher (诺埃尔·加勒格)在乐队的官网发布了这样一则声明:</p>
<p><span style="color: #3366ff;">It&#8217;s with some sadness and great relief to tell you that I quit Oasis tonight. People will write and say what they like, but I simply could not go on working with Liam a day longer. Apologies to all the people who bought tickets for the shows in Paris, Konstanz, and Milan.<br />
</span><span style="color: #333399;">(很遗憾同时也很宽慰地告诉你们，今晚我将退出Oasis。人们怎么说怎么写都可以，但我实在是不能再和Liam共处下去了，一天都不行。对于巴黎、康斯坦斯以及米兰的那些买了票的歌迷，我要说一声抱歉。)</span></p>
<p>有传闻说此事是因为他的弟弟，也就是乐队的主唱Liam Gallagher在巴黎与他发生了争执，Liam甚至还砸烂了Noel的吉他，于是Noel一气之下宣布离队。但是既然已经在官网发布声明，说明此事应该是正式的而非玩笑。没有了Noel的绿洲还是绿洲么？</p>
<div id="attachment_77" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-77" title="Gallagher兄弟，左为Liam，右为Noel" src="http://www.yinzhili.com/wp-content/uploads/2009/08/noel_liam.jpg" alt="Gallagher兄弟，左为Liam，右为Noel" width="500" height="352" /><p class="wp-caption-text">Gallagher兄弟，左为Liam，右为Noel</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.yinzhili.com/2009/08/noel-gallagher-quits-oasis.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
