Smarty/PHP エラー
Smarty は、タグの属性が不足していたり、誤った変数名を指定していた時など、
多くのエラーをキャッチする事ができます。
キャッチすると次の例のようなエラーが表示されます。
例 17-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 コンパイル時にパースエラーで終了します。
例 17-2. 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 ファイルを開いて行番号のあたりを調べる必要があります。
例 17-3. その他共通のエラー Warning: Smarty error: unable to read resource: "index.tpl" in...
or
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... |
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 /.. |
Fatal error: Smarty error: unable to write to $cache_dir '/... |
|
デバッグ、
$error_reporting
および
trigger_error()
の項も参照してください。