アプリ版:「スタンプのみでお礼する」機能のリリースについて

下記のコードを実行すると、

 Smarty error: unable to read resource: "template1.tpl"

 というエラーが出てしまいます。
$smarty->template_dirで指定したディレクトリ名の中に
 "template1.tpl"というファイルは配置してあります。
 原因などわかればおしえていただけないでしょうか。

index.php
<?php
require_once("Smarty.class.php");

$smarty = new Smarty;
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates_c/';
$smarty->config_dir = './configs/';
$smarty->cache_dir = './cache/';

$smarty->display("template1.tpl");
?>
【サーバ】
 ロリポップです。
【その他】
index.phpをホームディレクトリ配下におくとエラーは消えます。
【ディレクトリ構成】
modules/index.php と templates/template1.tpl をがあり、
index.php から template1.tpl を読み込もうとしています。

 ・modules
→index.php
・templates
→template1.tpl

A 回答 (2件)

template_dirの設定を相対ではなく絶対パスにしてしまえばいいのではないでしょうか。



ロリポの絶対パス
/home/sites/lolipop.jp/users/ドメイン名-ユーザー

こんな感じらしいので、
/home/sites/lolipop.jp/users/ドメイン名-ユーザー/templates/

とかってしておけば良いんじゃないかと思います。

この回答への補足

ご回答どうもありがとうございます!
上記のようにさせていただいたのですが、やはり状況は変わらず
同じエラーが出力しました。
権限の問題かと思い、試しにtplを「777」の権限で行ってもやはり同様でした。

読み込み元のphpファイルは、必ずホームディレクトリの直下でないと
いけないなどルールがあるのでしょうか?
または、直下でない場合、何か記述などが変わってくるのでしょうか?
もしわかれば教えてください。
どうぞよろしくおねがいいたします。

補足日時:2008/01/28 01:27
    • good
    • 0

index.phpから見れば


$smarty->template_dir = '../templates/';
になるのでは?

フルパスの方が確実だとは思いますが。
define('BASE_DIR', dirname(dirname(__FILE__)) . '/');
$smarty->template_dir = BASE_DIR . 'templates/';
$smarty->compile_dir = BASE_DIR . 'templates_c/';
    • good
    • 0
この回答へのお礼

確認が遅くなりすみません。
上記の通り実行したら、うまくいきました!
ディレクトリの構成などについてもっと勉強しないといけないですね・・。
どうもありがとうございました!

お礼日時:2008/01/31 01:37

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!