dポイントプレゼントキャンペーン実施中!

PHP+smartyを学んでいます。
Apache2-htdocs-taro-hanako.php とファイルを置き、一方、
Apache2-php_libs-smarty の下に
-libs/ (中にSmarty.class.php あり) と
-templates/ (中にtest.tpl あり)を並列的におきました。
hanako.php に、
require_once "../../php_libs/smarty/libs/Smarty.class.php";
$smarty = new Smarty;
$smarty->templete_dir = "../../php_libs/smarty/templates";
  $smarty->compile_dir = "../../php_libs/smarty/templates_c";
$smarty->cache_dir = "../../php_libs/smarty/cache";
以下省略・・・
と書いてブラウザで開くと、次のエラーが出て、tpl を読み込むことが出来ません。

Warning: Smarty error: unable to read resource: "test.tpl" in C:\Program Files\Apache Group\Apache2\php_libs\smarty\libs\Smarty.class.php on line 1088

どこを間違えているのでしょうか。

A 回答 (3件)

Windows版だとなにか違うんでしょうかねぇ・・・


私はUNIX版で同じソースを書いてみたのですが、
正常に動作してます。
ちなみに私はこんな風に書いてみました。
(全て同一ディレクトリ)
・taro.php
<?php
  require_once "config.php";
  $smarty = new Smarty;
  $smarty->compile_dir = $cpl_dir;
  $smarty->templete_dir = $cnf_dir;
  $smarty->cache_dir = $cch_dir;

$smarty->assign("lista",dog);
$smarty->assign("listb",cat);
$smarty->display($doc_root . "test.tpl");
?>
・test.tpl
  <html>
  lista={$lista}<br>
  listb={$listb}<br>
  </html>
・config.php
<?php
  require_once "/usr/local/share/smarty/Smarty.class.php";
  $doc_root ="/usr/local/www/data-dist/test/";
  $cpl_dir = '/usr/local/share/smarty/template_c';
  $cnf_dir = '/usr/local/share/smarty/configs';
  $cch_dir = '/usr/local/share/smarty/cache';
?>
これだとうまくいくんですが、おっしゃっている障害の
原因とは考えにくいですねぇ・・・
おそらく、「$smarty->display();」の部分がキモだとは思うのですが、
Windows版でやった事が無いので、あまり参考にならないかもしれません。
パスの書き方をいろいろと工夫してみてはいかがでしょうか?
Apache(で動かしてるのかな!?)のドキュメントルートからパスを書いて
見るとか・・・いろいろと。
    • good
    • 0
この回答へのお礼

yossy-55様
いろいろお手数をおかけし、お蔭様で解決の糸口を掴むことが出来ました。
ご示唆頂いた諸点を基礎にいろいろ調べ、試行錯誤した結果、解決しました!
やはり、Windowsのローカルルールがあったのです。
$smarty->display("file:絶対パス/test.tpl");
とすることで、hanako.phpをブラウザ上で実行して所期の画面を表示させることができました。
本当に有難うございました。

お礼日時:2007/03/05 19:58

コンパイルディレクトリは作ってますか?


C:\Program Files\Apache Group\Apache2\php_libs/smarty/templates_c
キャッシュディレクトリは作ってますか?
C:\Program Files\Apache Group\Apache2\php_libs/smarty/cache

$smarty->display("
C:\Program Files\Apache Group\Apache2\php-libs \smarty \libs \templates\test.tpl
");
とすると、どうなりますか?
例えば、config.phpをrequireして、中に
$tpl_root="C:\Program Files\Apache Group\Apache2\php-libs \smarty \libs \templates\";
等として、
hanako.phpに
require_once "config.php";を追加して
$smarty->display("test.tpl");を
$smarty->display("{$tpl_root}test.tpl");
としてみたらどうでしょう...

すみません。Windows版はあまりやった事無いので、付け焼刃かもしれませんが…

この回答への補足

hanako.phpの全文は次のように書いています。
<?php
require_once "../../php_libs/smarty/libs/Smarty.class.php";
$smarty = new Smarty;
$smarty->templete_dir = "../../php_libs/smarty/templates";
$smarty->compile_dir = "../../php_libs/smarty/templates_c";
$smarty->cache_dir = "../../php_libs/smarty/cache";

$smarty->assign('lista',dog);
$smarty->assign('listb',cat);
$smarty->display("test.tpl");
?>
---------------
config.phpでの確認はまだ出来ておりませんが、

$smarty->display("test.tpl")の ""の中を
1) ./test.tpl とした時の、エラーメッセージ
Warning: Smarty error: unable to read resource: "./test.tpl" in C:\Program Files\Apache Group\Apache2\php_libs\smarty\libs\Smarty.class.php on line 1088
2) ../../php_libs/smarty/templates/test.tpl とした時の、エラーメッセージ
Warning: Smarty error: unable to read resource: "../../php_libs/smarty/templates/tanukisample1.tpl" in C:\Program Files\Apache Group\Apache2\php_libs\smarty\libs\Smarty.class.php on line 1088
3) 絶対パスで書いた時の、エラーメッセージ
(絶対パスで書いているのにエラーメッセージが相対パスで示される。)
Warning: Smarty error: unable to read resource: "../../php_libs/smarty/templates/test.tpl" in C:\Program Files\Apache Group\Apache2\php_libs\smarty\libs\Smarty.class.php on line 1088

smartyの直下にlibsディレクトリとtemplates,templates_c,cache各ディレクトリを並列に置いていますが、
このパス指定の仕方が間違っているのでしょうか?

補足日時:2007/03/04 22:50
    • good
    • 0

大事な所が「以下略」となっている気がしますが…


$smarty->display("test.tpl");
""に囲まれている部分はどうなっているのでしょう?
ここのパスはあっていますか?

この回答への補足

有難うございます。
$smarty->display("test.tpl"); は、このまま、$smarty->display("test.tpl");となっていました。。。。。。
しかし、
$smarty->display("../../php_libs/smarty/templates/test.tpl");
としても、
Warning: Smarty error: unable to read resource: "../../php_libs/smarty/templates/test.tpl" in C:\Program Files\Apache Group\Apache2\php_libs\smarty\libs\Smarty.class.php on line 1088
となって、読み込めないですが。。。。。

補足日時:2007/03/04 18:48
    • good
    • 0

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