<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.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://www.jackxiang.com/post//</link>
<title><![CDATA[[朝花夕拾]smarty 打开报错提示（错误提示）并调试查看所有变量，smarty 调试打印数组及显示变量。直接查看编译结果看是否有smarty模板编译缓存。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Wed, 07 Sep 2011 12:39:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	一，调试模式查看所有变量和数组<br/><br/>1、设置配置文件中的 debuging的值为true。即开始调试（设置完这一步，一般情况下在浏览页面的时候就可以看到一个弹窗了，里面有在这个页面里的所有smarty变量。如果没有弹出看下一步）。<br/><textarea name="code" class="html" rows="15" cols="100">
//$smarty-&gt;debugging = false;
$smarty-&gt; debugging&nbsp;&nbsp; =&nbsp;&nbsp; true; //修改为false后即使模板里有 &#123;debug&#125;也不会弹出，Firefox要注意下让其弹出框。
$smarty-&gt; debug_tpl(&#039;debug.tpl&#039;);
</textarea><br/><br/><br/>2、在模版里输入&#123;debug&#125;，就可以看到这个模版里的变量了。<br/>如果要关闭掉调试控制台，设置变量 $debugging 为 false 就可以了。<br/><br/>不同的情况那个debug是不一样的，实际中特别注意要$tpl-&gt;caching = false;不能缓存时看全部DB输出的变量：<br/><textarea name="code" class="html" rows="15" cols="100">
$rootDir = APP_ROOT;
$tpl-&gt;template_dir = $rootDir;
$tpl-&gt;compile_dir = $rootDir . &quot;templates_c/&quot;;
//$tpl-&gt;config_dir = APP_ROOT . &quot;configs/&quot;;
$tpl-&gt;cache_dir = $rootDir . &quot;cache/&quot;;
$tpl-&gt;left_delimiter = &#039;&lt;&#123;&#039;;
$tpl-&gt;right_delimiter = &#039;&#125;&gt;&#039;;
$tpl-&gt;caching = false;
$tpl-&gt; debugging&nbsp;&nbsp; =&nbsp;&nbsp; true;&nbsp;&nbsp;
</textarea><br/><br/>在模板中是这样：<br/><textarea name="code" class="html" rows="15" cols="100">
&lt;&#123;debug&#125;&gt;
</textarea><br/><br/>在smarty编译后的模板里是这样的：<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php require_once(SMARTY_CORE_DIR . &#039;core.load_plugins.php&#039;);
smarty_core_load_plugins(array(&#039;plugins&#039; =&gt; array(array(&#039;function&#039;, &#039;debug&#039;, &#039;partner/include/left.html&#039;, 1, false),)), $this); ?&gt;
&lt;?php echo smarty_function_debug(array(), $this);?&gt;
</textarea><br/><br/>要想能真正报错其实践的结论是，三个都打开：<br/>1.error_reporting(E_ALL);打开，否则有错容易报不出来:<br/><textarea name="code" class="php" rows="15" cols="100">error_reporting(E_ALL);</textarea><br/>2.$tpl-&gt;debugging = true;<br/><textarea name="code" class="php" rows="15" cols="100">
define( &quot;APP_ROOT&quot;, dirname(dirname(dirname(__FILE__))).&quot;/&quot;);
require_once(APP_ROOT.&quot;php/lib/smarty/Smarty.class.php&quot;);
$rootDir = APP_ROOT;
$tpl = new extSmarty();

$tpl-&gt;register_resource(&#039;text&#039;, array(
&nbsp;&nbsp;&nbsp;&nbsp;&#039;smarty_resource_text_get_template&#039;,
&nbsp;&nbsp;&nbsp;&nbsp;&#039;smarty_resource_text_get_timestamp&#039;,
&nbsp;&nbsp;&nbsp;&nbsp;&#039;smarty_resource_text_get_secure&#039;,
&nbsp;&nbsp;&nbsp;&nbsp;&#039;smarty_resource_text_get_trusted&#039;)
);
$tpl-&gt;debugging = true;&nbsp;&nbsp;//设置配置文件中的 debuging的值为true。
$tpl-&gt;template_dir = $rootDir;
$tpl-&gt;compile_dir = $rootDir . &quot;templates_c/&quot;;
//$tpl-&gt;config_dir = APP_ROOT . &quot;configs/&quot;;
$tpl-&gt;cache_dir = $rootDir . &quot;cache/&quot;;
$tpl-&gt;left_delimiter = &#039;&lt;&#123;&#039;;
$tpl-&gt;right_delimiter = &#039;&#125;&gt;&#039;;
$tpl-&gt;caching = false;
</textarea><br/>3.在输出页面里加入调试变量：<br/><textarea name="code" class="php" rows="15" cols="100">&lt;&#123;debug&#125;&gt;</textarea><br/>二，非调试模式下查看变量和数组，也就是从弹出框中所有变量只看一部分，以方便调试。<br/><br/>1、Smarty下如何查看数组：<br/>&nbsp;&nbsp; 如果你在使用smarty时，想查看某变量的内容，而又不想打开smarty debug，或smarty debug的输出不能满足你的要求，可以这样用。<br/>如果是查看数组，应当<br/><textarea name="code" class="html" rows="15" cols="100">
&#123;$var&#124;@print_r&#125;
</textarea><br/>我自己试了下是这样：<br/><textarea name="code" class="html" rows="15" cols="100">
&lt;&#123;$busiStat&#124;@print_r&#125;&gt;
</textarea><br/>会输出到页面里，不是弹出框。<br/>注意：这里用@是来保证把变量当做一个整体对待，否则会遍历这个array.<br/>查看变量：<br/><textarea name="code" class="html" rows="15" cols="100">
&#123;$var&#124;print_r&#125;
</textarea><br/><br/><br/>2、Smarty下如何调试数组，无论这个：$tpl-&gt; debugging&nbsp;&nbsp; =&nbsp;&nbsp; TRUE;&nbsp;&nbsp;或者：False都可以：<br/>比如要调试数组$array<br/><textarea name="code" class="html" rows="15" cols="100">
&nbsp;&nbsp;&nbsp;&nbsp;&#123;$array&#124;@debug_print_var&#125;
</textarea><br/>实践如下：<br/><textarea name="code" class="html" rows="15" cols="100">
&lt;&#123;$busiStat&#124;@debug_print_var&#125;&gt;
</textarea><br/><br/>调试变量就<br/><textarea name="code" class="html" rows="15" cols="100">
&nbsp;&nbsp;&nbsp;&nbsp;&#123;$var&#124;debug_print_var&#125;
</textarea><br/>偶的实践：<br/><textarea name="code" class="html" rows="15" cols="100">
&lt;&#123;$SCRIPT_NAME&#124;debug_print_var&#125;&gt;
</textarea><br/><br/>请注意：数组都有一个@，呵呵。<br/>详细说请看Smarty/plugins下的modifier.debug_print_var.php<br/><br/>本站内相关文章三篇：<br/>http://www.jackxiang.com/post/2083/<br/>http://www.jackxiang.com/post/1169/<br/>http://www.jackxiang.com/post/1191/<br/><br/><br/>直接查看编译结果看是否有smarty模板编译缓存(有时配置文件没配置好出现模板里没有变量，得查找老半天，直接查看编译好的模板能快速找到线索Add：2014-01-09):<br/>一）生成Js的Url地址如下：<br/>http://static.xiyou.cntv.cn/2013/js/wistracker.js?ver=2.037<br/>二）配置前缀路径：<br/>config.php<br/>return array(<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;statistics&#039; =&gt; array(<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;action_url&#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; &#039;http://static.xiyou.cntv.cn/2013/js/&#039;<br/>&nbsp;&nbsp;&nbsp;&nbsp;)<br/>)<br/>三）smarty输出到模板：<br/>./application/controllers/front/frontbase.php:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;view-&gt;user_action = KO::config(&#039;config.statistics.action_url&#039;);<br/><br/><br/>四）模板编译情况：<br/>[root@my smarty_compile]# vi ./%%D3^D36^D3641954%%index.html.php<br/>&lt;script src=&quot;&lt;?php echo $this-&gt;_tpl_vars[&#039;user_action&#039;]; ?&gt;<br/>wistracker.js?ver=&lt;?php echo $this-&gt;_tpl_vars[&#039;version&#039;]; ?&gt;<br/>&quot; type=&quot;text/javascript&quot;&gt;
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [朝花夕拾]smarty 打开报错提示（错误提示）并调试查看所有变量，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://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>