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()。
�� 调试。
