![](http://oshiete.xgoo.jp/images/v2/pc/qa/question_title.png?5a7ff87)
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で質問しましょう!
似たような質問が見つかりました
- その他(プログラミング・Web制作) カラーミーのSmarty構文について 1 2022/10/09 13:55
- PHP カラーミーショップのSmartyでの文字列抜き出し 2 2022/05/06 11:51
- JavaScript カラーミーショップのsectionループ内で、[引数][戻り値]ありの関数的な処理を行いたいです。 1 2022/05/07 19:39
- PHP 掲示板を作成しておりアップロードファイルとメッセージを並べたいので、アドバイスお願い致します 2 2023/07/17 21:01
- PHP アップロード画像数でCSSを分けることに成功したのですが、画像の横に文字を並べることが出来ません。 3 2023/07/28 17:16
- PHP ランキングを表示する際の画像の大きさを固定することは可能でしょうか? <?php if ( has_ 1 2022/07/21 14:55
- HTML・CSS CSSが効かずどのように指定すれば良いか分からないのでアドバイスお願い致します 2 2023/06/07 12:25
- PHP アップロードファイルの数に応じてCSSを動的に変更したいのですが、方法がわかりません 3 2023/07/23 21:59
- PHP 共通の処理をまとめる方法がわからないのでアドバイスお願いします。 1 2022/12/19 20:20
- JavaScript clear機能を失わずにファイルアップロード機能を作成したい 3 2023/06/10 16:12
関連するカテゴリからQ&Aを探す
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
phpで距離÷時間の方法
-
XMLのロードに失敗する
-
PHPのif文でその処理を途中で抜...
-
【file_exists】ファイルが存在...
-
onedrive にexcelファイルをア...
-
拡張子php画像をjpg画像等に変...
-
youtubeに音声のみのmp4ファイ...
-
PHPのMySQLモジュールのインス...
-
pixivのイラスト投稿の仕方を教...
-
javascriptからphpへ変数
-
PHPで作るフレーム、どんな風に...
-
PHPで外部プログラムのバックグ...
-
FTPでのファイルとディレクトリ...
-
ファイルアップロードの上限を...
-
フレームワークの選定について
-
ヒアドキュメントの中で別ファ...
-
PHP8を使うと、大量のWarningが...
-
さくらサーバーにて、phpからメ...
-
PHP MySQLに画像を直接保存
-
localhostでphpのページが表示...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
PHPってなんの略?
-
smartyテンプレート読み込みに...
-
PHPフレームワーク環境でのSmar...
-
phpでサブルーチン
-
Smartのカスタマイズでエラー
-
smarty3で変数表示について
-
Codeigniterの使い方を教えてい...
-
PHPの関数って何種類ありますか?
-
フォントの色を変えるには?
-
onedrive にexcelファイルをア...
-
PHPのif文でその処理を途中で抜...
-
こちらはただの直列処理ですか?
-
別ファイルの変数を呼び出した...
-
PHP8を使うと、大量のWarningが...
-
トランザクションが原因?DBに...
-
form actionで二つ送信先を指定...
-
FTPコマンドでディレクトリごと...
-
.phpと.incファイルの違いはな...
-
VBSの「MsgBox」について
-
ワードプレス、Contact Form 7...
おすすめ情報