<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[[Smarty]Smarty模板学习,测试通过！！]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Sun, 07 Jan 2007 04:35:21 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	<p align="left">Smarty是一款PHP官方支持的模板，有点小复杂。<br/><br/>重要的是LIBS这个目录，以及在数据文件中，对“templates”，“templates_c”，“configs”以及“cashe”四个目录的设定；什么地方可以放模板，什么地方可以放数据，确实让开始学习的我头痛了一番。<br/><br/><br/>比如，我要写一个 HelloWorld 程序，步骤如下：<br/><br/>&nbsp;&nbsp; 1. 到 SMARTY 下载稳定的SMARTY包。<br/>&nbsp;&nbsp; 2. 在APACHE相应目录下面，新建一个文件夹：“helloworld”。<br/>&nbsp;&nbsp; 3. 将下载下来的smarty包内的“libs”文件夹完完全全的拷贝到“helloworld”文件夹。<br/>&nbsp;&nbsp; 4. 接下来就是最最恶心的一步了，你需要在“helloworld”手工新建四个文件夹：“cashe”、“configs”、“templates”，“templates_c”（不要修改文件夹名称），这四个文件将与“libs”文件夹并行。<br/>&nbsp;&nbsp; 5. 我们接着写一个模板文件，是的，它必须安放在“templates”文件夹下面（不要问我为什么，其实我也不知道~），你可以将它命名为index.tpl，或者index.html，推荐前者（smarty的模板格式，虽然我觉得其内容和html没有什么区别），输入如下代码：<br/><br/><div class="code">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. &lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. &lt;html&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3. &lt;head&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4. &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5. &lt;title&gt;Smarty&lt;/title&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6. &lt;/head&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7. &lt;body &gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8. &#123;$hello_templates&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9. &lt;/body&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10. &lt;/html&gt;</div><br/>&nbsp;&nbsp; 6. 接着，我们需要写一个数据文件，这个才是重头。在“helloworld”根目录下面，新建一个index.php文件，写入如下代码：<br/><br/><div class="code">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. &lt;?php<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. //引用类文件<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3. require &#039;/libs/Smarty.class.php&#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4.&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5. $smarty = new Smarty;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6.&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7. //设置各个目录的路径，这里是安装的重点<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8.&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9. $smarty-&gt;template_dir = &quot;templates&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10.&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;11. $smarty-&gt;compile_dir = &quot;templates_c&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;12. $smarty-&gt;config_dir = &quot;config&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13. $smarty-&gt;cache_dir = &quot;cache&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;14.&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;15. //smarty模板有高速缓存的功能，如果这里是true的话即打开caching，但是会造成网页不立即更新的问题，当然也可以通过其他的办法解决<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16. $smarty-&gt;caching = false;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;17.&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;18. //赋值<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;19. $smarty-&gt;assign(&quot;hello_templates&quot;,&quot;Hello World!&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20.&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;21. //引用模板文件，注意这里的index.tpl路径，不是真实的路径，不用写成/templates/index.tpl样式<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;22. $smarty-&gt;display(&#039;index.tpl&#039;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;23.&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;24. ?&gt;</div></p><br/>如果出现找不到文件：可能是如下变量设置或者默认设置有问题：<br/><div class="code"><br/>$tpl-&gt;template_dir = &quot;./aaa&quot;;//修改到aaa目录，默认是templates，这个aaa和templates是一个层级的，然后放入模板文件即可！<br/>echo $tpl-&gt;template_dir;<br/>echo $tpl-&gt;config_dir ;<br/>echo $tpl-&gt;compile_dir;<br/>echo $tpl-&gt;cache_dir;</div>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [Smarty]Smarty模板学习,测试通过！！]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>