跳至内容

故障排除

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...

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 '/...
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()

另请参阅 调试