Smartyで階層を分けた時にいちいちつまずいた恥ずかしい初心者あるある
Smartyをルート階層に置き、ルート階層以外のところで使用することになった。
project / | +-- blog / index.php | ●●.php | ●●.php | ●●.php +-- smarty / Config_File.class.php | debug.tpl | Smarty.class.php | Smarty_Compiler.class.php
こんな感じ。
Smarty超初心者の自分はもちろんこう記載するわけです
<?php require_once('../libs/Smarty.class.php'); $smarty = new Smarty; $smarty->display('test.tpl'); ?>
するとこんなエラーが出現するわけです。
Fatal error: Uncaught --> Smarty: Unable to load template file 'test.tpl' <-- thrown in C:\pleiades\xampp\htdocs\jukujo_contact\libs\sysplugins\smarty_internal_templatebase.php on line 129
templatesまでのパスが上手く設定できてないのが原因。
PHPでしっかり明記してやったら解決した。
<?php require_once('../libs/Smarty.class.php'); $smarty = new Smarty; $smarty->template_dir = "../templates"; $smarty->compile_dir = "../templates_c"; $smarty->display('test.tpl'); ?>
始めたての言語とかってこういうしょうもないあるあるがあるね。
でもここからベテランになっていくのだよwww