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
どこを間違えているのでしょうか。
No.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(で動かしてるのかな!?)のドキュメントルートからパスを書いて
見るとか・・・いろいろと。
yossy-55様
いろいろお手数をおかけし、お蔭様で解決の糸口を掴むことが出来ました。
ご示唆頂いた諸点を基礎にいろいろ調べ、試行錯誤した結果、解決しました!
やはり、Windowsのローカルルールがあったのです。
$smarty->display("file:絶対パス/test.tpl");
とすることで、hanako.phpをブラウザ上で実行して所期の画面を表示させることができました。
本当に有難うございました。
No.2
- 回答日時:
コンパイルディレクトリは作ってますか?
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各ディレクトリを並列に置いていますが、
このパス指定の仕方が間違っているのでしょうか?
No.1
- 回答日時:
大事な所が「以下略」となっている気がしますが…
$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
となって、読み込めないですが。。。。。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
フォームで戻った際に入力済み...
-
phpでcookieがうまく保存されない
-
ファイルの書き込みについて教...
-
アップロードファイルを表示す...
-
【スプレッドシート】順位のつけ方
-
htmlspecialcharsが機能してい...
-
PHP MySQLに画像を直接保存
-
返信機能のツリー構造の深さを...
-
ワードプレスプラグイン MW WP ...
-
重複を防ぐ記述について教えて...
-
PHPで画像の渡しが上手く行きま...
-
「ログイン機能を持たせる」説...
-
「teratail」での回答内容がい...
-
1 OR 1=1 は どんな論理(約束事...
-
複数のパソコンの中の1つのパソ...
-
PHPについて。
-
phpのheader("Location:#pos")...
-
PHPからCSVをアップロード後、m...
-
[php初心者]サイトを見てデータ...
-
phpに関わる所での、form actio...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
xserver Smarty PHP+MySQL
-
Codeigniterの使い方を教えてい...
-
Smarty tpl内のifの書き方について
-
phpでサブルーチン
-
PHPってなんの略?
-
Pleskサーバ利用時にSmartyのas...
-
phpの互換性について
-
Smartのカスタマイズでエラー
-
tplを読みに行けません。
-
php fork
-
いつもお世話になっております。
-
PHPのcrypt関数について
-
Smartyのif構文について
-
smartyテンプレート読み込みに...
-
PHPでのページ送り機能
-
エクリプスのソフトでPHPを...
-
onedrive にexcelファイルをア...
-
PHPのif文でその処理を途中で抜...
-
フォントの色を変えるには?
-
違法アップロードについて
おすすめ情報