What is Smarty?
Why use it?
Use Cases and Work Flow
Syntax Comparison
Template Inheritance
Best Practices
Crash Course
You may use the Smarty logo according to the trademark notice.
For sponsorship, advertising, news or other inquiries, contact us at:
Table of Contents
Smarty可以捕获多种错误,如错误的标签、写错的变量名等等。 如果发生这些错误,Smarty将如下提示:
Example 20.1. Smarty 错误
Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah' in /path/to/smarty/Smarty.class.php on line 1041 Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name in /path/to/smarty/Smarty.class.php on line 1041
Smarty会显示模板名字,错误行数和错误内容。 还会接着显示在Smarty类文件真实错误发生的行数。
部分错误是Smarty无法捕获的。如忘记了写分号等。 这种类型一般会在PHP编译时直接提示。
Example 20.2. PHP 错误提示
Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
当提示PHP错误,系统会提示Smarty已编译的PHP文件出错的行数,
而不是模板代码的行数。
一般你可以查看模板代码并且寻找出错的代码。
下面是一些通常可以检查的地方:
是否丢失了关闭标签如{if}{/if}
或者
{section}{/section}
, 或是{if}
标签内的逻辑等。.
如果无法找到错误位置,你可以打开已编译的PHP文件来定位问题,然后这对应找出模板的错误位置。
Example 20.3. 其他的常见错误
Warning: Smarty error: unable to read resource: "index.tpl" in... or Warning: Smarty error: unable to read resource: "site.conf" in...
$template_dir
出现的错误, 在
templates/
目录中
不存在index.tpl
文件。
{config_load}
函数,(或调用
configLoad()
函数)
,$config_dir
出现的错误,目录中找不到site.conf
文件。
Fatal error: Smarty error: the $compile_dir 'templates_c' does not exist, or is not a directory...
$compile_dir
不正确,目录不存在;或者
templates_c
不是目录而是文件。
Fatal error: Smarty error: unable to write to $compile_dir '....
$compile_dir
在服务器上无法写入文件。
关于文件权限问题,参考下面
Smarty安装的文章。
Fatal error: Smarty error: the $cache_dir 'cache' does not exist, or is not a directory. in /..
这意味着,
$caching
已经开启,
但$cache_dir
不正确,目录不存在;或者
cache/
不是目录而是文件。
Fatal error: Smarty error: unable to write to $cache_dir '/...
这意味着,$caching
已经开启,
$cache_dir
在服务器上无法写入文件。
关于文件权限问题,参考下面
Smarty安装的文章。
Warning: filemtime(): stat failed for /path/to/smarty/cache/3ab50a623e65185c49bf17c63c90cc56070ea85c.one.tpl.php in /path/to/smarty/libs/sysplugins/smarty_resource.php
这意味着,你的应用程序已经注册了自定义错误处理器(使用
set_error_handler()),
但该处理器没有处理当前的$errno
。
如果,不管什么理由,这是你的自定义错误处理器的处理方式的话,
那么在注册你的错误处理器后,调用
muteExpectedErrors()
。
参见 调试。