Skip to content

故障排查

Smarty/PHP 错误

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 编译时解析错误。

Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75

当你遇到 PHP 解析错误时,错误行号将对应于编译的 PHP 脚本,而不是模板本身。通常你可以查看模板并发现语法错误。这里有一些常见的错误:缺少{if}{/if}{section}{/section}的关闭标签,或者{if}标签内的逻辑语法。如果你找不到错误,可能需要打开编译的 PHP 文件,转到行号,找出模板中对应的错误。

Warning: Smarty error: unable to read resource: "index.tpl" in...

Warning: Smarty error: unable to read resource: "site.conf" in...
  • $template_dir可能设置错误,不存在,或者文件index.tpl不在templates/目录中。

  • 模板中有一个{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 '....
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 '/...
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()

参见 调试