• 締切済み

smarty3で変数表示について

smarty3 でエラーが発生しています。 現在自宅のサーバーでsmarty3を勉強しているのですが以下のエラーで困っています。 詳しい方ご教授お願いします。 環境 : CentOS 6.3 PHP 5.3.3 Smarty 3.1.13 読み込んでいるファイル test.php 1 <?php 2 ini_set('display_errors', 1); 3 ini_set('date.timezone','Asia/Tokyo'); 4 define('SMARTY_DIR', 'Smarty/libs/'); 5 require_once( SMARTY_DIR. 'Smarty.class.php'); 6 7 $smarty = new Smarty(); 8 9 $smarty->template_dir = '../templates/'; 10 $smarty->compile_dir = '../templates_c/'; 11 $smarty->config_dir = '../config/'; 12 $smarty->cache_dir = '../cache/'; 13 14 $msg = "テストを表示します"; 15 $smarty->assign('msg', $msg); 16 17 $smarty->display('test.tpl'); 18 19 20 ?> テンプレートファイル 1 <html> 2 {$msg} 3 </html> 表示されるエラー文 Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "../templates/test.tpl" on line 2 "{$msg}" unknown tag "private_print_expression"' in /usr/local/lib/php/includes/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php:665 Stack trace: #0 /usr/local/lib/php/includes/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php(451): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "pr...', 2) #1 /usr/local/lib/php/includes/Smarty/libs/sysplugins/smarty_internal_templateparser.php(2353): Smarty_Internal_TemplateCompilerBase->compileTag('private_print_e...', Array, Array) #2 /usr/local/lib/php/includes/Smarty/libs/sysplugins/smarty_internal_templateparser.php(3101): Smarty_Internal_Templateparser->yy_r27() #3 /usr/local/lib/php/includes/Smarty/libs/sysplugins/smarty_internal_templateparser.php(3201): Smarty_Internal_Templateparser->yy_reduce(27) #4 /usr/local/lib/php/includes/Smarty/libs/sysplugins/smarty_intern in /usr/local/lib/php/includes/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 665 テンプレートファイルの{$msg}を削除して動作させるとコンパイルされてはいるようです。 よろしくお願いします。

  • PHP
  • 回答数2
  • ありがとう数0

みんなの回答

  • coai
  • ベストアンサー率50% (152/301)
回答No.2

以下の事例が現象(というかエラーメッセージ)が似てるな http://www.smarty.net/forums/viewtopic.php?p=69968 『なんてこった、サーバ上の「templates_c」ディレクトリにパーミンション777を設定してみたんだ。そしたらちゃんと動いた』 だと。 >テンプレートファイルの{$msg}を削除して動作させるとコンパイルされてはいるようです。 という事なので、現象は違うかも知れないが…念のためパーミッションの確認を。 他にも、『/libs/sysplugins ディレクトリをちゃんとアップしてないか、パーミッションの関係で読みとれてないんじゃねえの?』と推測している人も居るようなので、その点も確認してみてください。

回答No.1

>9 $smarty->template_dir = '../templates/'; >10 $smarty->compile_dir = '../templates_c/'; >11 $smarty->config_dir = '../config/'; >12 $smarty->cache_dir = '../cache/'; 原因はこれ。 どうしてこの部分かは、日本語のリファレンスと英語のリファレンスを見比べると どうしてかがわかる。

関連するQ&A

  • Smartyについて

    Smartyについて Smartyをインストールしました。 OS:ubuntu インストール先:/usr/local/lib/Smarty-2.6.26 php.ini[include_path]の設定:/usr/local/lib/Smarty-2.6.26/libs/を追加 /var/www/以下にtestフォルダ作成 /var/www/test/index.html | /test/index.php chmod 644 | /tempalates chmod 775 templates | / index.tpl chmod 644 /templates_c chmod 775 templates_c /configs chmod 775 configs /cache chmod 775 cache index.phpの内容 <?php require_once(”Smarty.class.php"); $o_smarty=new Smarty(); $o_smarty->template_dir="./templates/"; $o_smarty->compile_dir="./template_c/"; $o_smarty->assign("name","world"); $o_smarty->display("hello.tpl"); ?> index.tplの内容 <html> <head> <title>Hello,world</title> </head> <body> Hello,{$name}! </body> </html> http://web.domain/test/index.php を入力するとエラーは出ませんが、何も表示されません。 これだけで、原因を特定出来ないのかもしれませんが、何処が悪いのでしょうか? 御教示お願いいたします。

  • Smarty3のリソース・プラグイン

    Smarty3のリソース・プラグインについて Smarty3(3.0.9)でリソース・プラグインを行うと以下エラーが出力され、データベース内のテンプレートを呼び出すことができません。 Uncaught exception 'SmartyException' with message 'Unable to load template db 'test.tpl'' in /usr/local/lib/php/smarty/sysplugins/smarty_internal_template.php:165 Stack trace: #0 /usr/local/lib/php/smarty/sysplugins/smarty_internal_template.php(554): Smarty_Internal_Template->isExisting(true) #1 /usr/local/lib/php/smarty/Smarty.class.php(340): Smarty_Internal_Template->getRenderedTemplate() #2 /usr/local/lib/php/smarty/Smarty.class.php(384): Smarty->fetch('test.tpl', NULL, NULL, NULL, true) #3 /usr/local/apache2/htdocs/test.php(18): Smarty->display('test.tpl') #4 {main} thrown in /usr/local/lib/php/smarty/sysplugins/smarty_internal_template.php on line 165 同様のプログラムでSmarty2*で実行するとうまく表示します。 Smarty3のマニュアル(英語版)を見てもうまくいきません。。 ご存知の方、ぜひ教えてください。 (環境) OS:Debian 6.0.1 WebServer:Apache2.2.19 PHP:PHP5.3.6 MySQL:MySQL5.0.87 (プラグイン) <?php require('DB.php'); define("DB_FILE","mysqli://*****:*****@localhost/*****"); function smarty_resource_db_source ($name, &$source, $o_smarty) { $db = DB::connect(DB_FILE); $stt = $db->prepare("SELECT source FROM templates WHERE name =?"); $rs = $db->execute($stt,array($name)); if(is_null($row=$rs->fetchRow(DB_FETCHMODE_ASSOC))){ return FALSE; }else{ $source=$row["source"]; return TRUE; } } function smarty_resource_db_timestamp($name, &$modified, $o_smarty) { $db = DB::connect(DB_FILE); $stt = $db->prepare("SELECT * FROM templates WHERE name =?"); $rs = $db->execute($stt,array($name)); if(is_null($row=$rs->fetchRow(DB_FETCHMODE_ASSOC))){ return FALSE; }else{ $modified=$row["modified"]; return TRUE; } } function smarty_resource_db_secure($name, $o_smarty) { // 全てのテンプレートがセキュアであると仮定します return true; } function smarty_resource_db_trusted($name, $o_smarty) { // テンプレートから使用しません } ?> (呼び出しファイル) <?php set_include_path('/usr/local/lib/php/smarty/:' . get_include_path()); @include('Smarty.class.php'); $o_smarty = new Smarty(); // Smartyのテンプレートのキャッシュファイル格納先を指定 $o_smarty->compile_dir = "/usr/local/apache2/htdocs/template_c"; $o_smarty->plugins_dir[]="/usr/local/apache2/htdocs/plugin"; $o_smarty->default_resource_type="db"; // phpスクリプトからテンプレートリソースを使用します $o_smarty->display("test.tpl"); ?> (データベース) CREATE TABLE templates ( name VARCHAR(100) NOT NULL default '', modified TIMESTAMP, source TEXT, PRIMARY KEY (name) ) DEFAULT CHARACTER SET utf8; -- Dumping data for table 'templates' INSERT INTO templates VALUES('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');

    • 締切済み
    • PHP
  • Smartyエラーについて

    いつもお世話になっております。 Smartyのエラーが解決できなくて困っています。 お手数ですが、後教授願えないでしょうか。 使用環境:Ubuntu Eclipse [エラー] Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'list.tpl'' in /home/mobapendev/public_html/Smarty/sysplugins/smarty_internal_template.php:163 Stack trace: #0 /home/mobapendev/public_html/Smarty/sysplugins/smarty_internal_template.php(550): Smarty_Internal_Template->isExisting(true) #1 /home/mobapendev/public_html/Smarty/Smarty.class.php(338): Smarty_Internal_Template->getRenderedTemplate() #2 /home/mobapendev/public_html/Smarty/Smarty.class.php(382): Smarty->fetch('list.tpl', NULL, NULL, NULL, true) #3 /home/mobapendev/public_html/mobapen/list.php(20): Smarty->display('list.tpl') #4 {main} thrown in /home/mobapendev/public_html/Smarty/sysplugins/smarty_internal_template.php on line 163 ディレクトリ構成 Smarty/Smarty.class.php Project/list.php Project/php/common.php project/smarty/templates/list.tpl project/smarty/templates_c project/smarty/cache project/smarty/configs となっており、 common.phpにて、 $dir = getcwd(); $smarty->template_dir=$dir .'/smarty/templates'; $smarty->compile_dir=$dir .'/smarty/templates_c'; $smarty->config_dir=$dir .'/smarty/configs'; $smarty->cache_dir =$dir .'/smarty/cache'; list.phpにて require_onceで取り込みまいしたが、 $smarty->display("list.tpl"); ディレクトリは間違っていないとは思っているのですが、 どこでload出来てていなか分からず、攻め上げいている状況です。 以上、宜しくお願い致します。

    • ベストアンサー
    • PHP
  • smartyテンプレート読み込みについて

    Smarty動的Webサイト構築入門という書籍を見ながらSmartyを学習しているのですが、書籍のCD-ROMから落としたサンプルファイルを保存しているのですがどうしてもテンプレートを読み込むことができません。 03_01.php <?php require_once("../smarty/libs/Smarty.class.php"); $smarty = new Smarty(); $smarty->template_dir = "templates"; $smarty->compile_dir = "templates_c"; $smarty->assign("name", "Smartyさん"); $smarty->display("03_01.tpl"); ?> 03_01.tpl Hello, {$name}!! エラーメッセージ Warning: Smarty error: unable to read resource: "03_01.tpl" in C:\xampp\htdocs\smartybook\smarty\libs\Smarty.class.php on line 1092 03_01.phpは、C:\xampp/htdocs/smartybook/ren/に保存しています。 03_01.tplは、C:\xampp/htdocs/smartybook/templates/に保存しています。 どこが駄目なのか教えてください。 宜しくお願いします。

    • 締切済み
    • PHP
  • ロリポップでSmartyのtpl読み込みエラー

    下記のコードを実行すると、  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

    • ベストアンサー
    • PHP
  • Smartのカスタマイズでエラー

    いつもお世話になっております。 Smartyのカスタマイズを行いたく 設置でエラーになってしまいました。 public_htmlと同じ階層にSmartyフォルダを作成しました。 (下記のような構造になっています。) /public_html/ /Smart/configs/ /Smart/lib/ /Smart/templates/ /Smart/templates_c/ ファイルには下記のように記述しております。 /Smart/lib/smarty_setup.php ---------------------------------------- require_once 'Smarty.class.php'; class SmartySetup extends Smarty {  function SmartySetup() {   $this->template_dir = SMARTY_DIR . "templates";   $this->compile_dir = SMARTY_DIR . "templates_c";   $this->cache_dir = SMARTY_DIR . "cache";   $this->config_dir = SMARTY_DIR . "configs";   $this->left_delimiter = "<!--{";   $this->right_delimiter = "}-->";  } } ---------------------------------------- /public_html/smarty.php ---------------------------------------- require_once("../../Smarty/libs/smarty_setup.php"); $smarty = new Smarty(); $smarty->display("smarty.tpl"); ---------------------------------------- 実行すると、下記のようなエラーが表示されてしまいます。 Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'smarty.tpl'' in C:\*****\Smarty\libs\sysplugins\smarty_internal_template.php:163 Stack trace: #0 C:\*****\Smarty\libs\sysplugins\smarty_internal_template.php(541): Smarty_Internal_Template->isExisting(true) #1 C:\*****\Smarty\libs\Smarty.class.php(337): Smarty_Internal_Template->getRenderedTemplate() #2 C:\*****\Smarty\libs\Smarty.class.php(381): Smarty->fetch('smarty.tp...', NULL, NULL, NULL, true) #3 C:\*****\smarty.php(26): Smarty->display('smarty.tp...') #4 {main} thrown in C:\*****\Smarty\libs\sysplugins\smarty_internal_template.php on line 163 どう対処すればいいでしょうか。 よろしくご教示お願いいたします。

    • ベストアンサー
    • PHP
  • Smartyについて教えてください。

    Smartyについて教えてください。 参考書によってテンプレートの存在するディレクトリを指定している場合(1)と していない場合(2)がありますが、 どちらが正しいのでしょうか? (1) ********************************************* require_once('smarty/libs/Smarty.class.php'); $smarty = new Smarty(); $smarty->template_dir = "template02/"; $smarty->compile_dir = "compile/"; $smarty->display("content.tpl"); ********************************************* (2) ********************************************* require_once('smarty/libs/Smarty.class.php'); $smarty = new Smarty(); $smarty->display("content.tpl"); *********************************************

    • ベストアンサー
    • PHP
  • さくらレンタルサーバでのsmartyの設定

    プログラム初心者なのですが、以下教えて頂けないでしょうか。 さくらレンタル(スタンダード)にsmartyを設置を試みているのですが、エラーメッセージが出てしまいます。 環境:PHP 5.2.6 / Smarty 2.6.19 /home/(アカウント)/www/libs/smartyの直下にSmarty.class.php以下、公式サイトからダウンロードしたものをそのままアップし、/home/アカウント/www/smartytest/helloの直下に以下のファイルをアップしました。 (index.php) <?php define('SMARTY_DIR','/home/アカウント/www/libs/smarty/'); define('SMARTY_TEST','/home/アカウント/www/smartysample/hello/'); require_once(SMARTY_DIR.'Smarty.class.php'); $smarty = new Smarty; $smarty->template_dir = SMARTY_TEST.'templates/'; $smarty->compile_dir = SMARTY_TEST.'templates_c/'; $smarty->config_dir = SMARTY_TEST.'configs/'; $smarty->cache_dir = SMARTY_TEST.'cache/'; $smarty->assign('msg','Hello World!'); $smarty->display('index.tpl'); ?> そして、このindex.phpにアクセスすると、下記のようなエラーメッセージが表示されます。 Warning: Smarty::require_once(/home/アカウント/www/libs/smarty/internals/core.write_compiled_resource.php) [smarty.require-once]: failed to open stream: No such file or directory in /home/アカウント/www/libs/smarty/Smarty.class.php on line 1429 Fatal error: Smarty::require_once() [function.require]: Failed opening required '/home/アカウント/www/libs/smarty/internals/core.write_compiled_resource.php' (include_path='.:/usr/local/php-5.2.6/lib/php') in /home/アカウント/www/libs/smarty/Smarty.class.php on line 1429 Smarty.class.phpの1429行目に問題があるのかとファイルを開いてみたものの、初心者のためよく理解できません。あと、Smarty.class.phpを呼び出すのに絶対パスを指定しているのは、さくらの管理画面からphp.iniでinclude_pathを指定しようとしても、うまくいかなかったためです(上記の場合、$smarty = new Smarty;を削除すれば、エラー画面は表示されません。変わりに何も表示されませんが・・)。 初心者のため、基本的なところで見落としがあるのかもしれませんが、教えて頂ければと思います。どうか、宜しくお願いします。

    • 締切済み
    • PHP
  • Smartyに関しまして

    require_once("Smarty/Smarty.class.php"); $smarty = new Smarty(); $smarty->template_dir = "./templates"; $smarty->compile_dir = "./templates_c"; $smarty->assign("message", "こんばんは"); $a = array('hello','php','html'); $smarty->assign('a',$a); $smarty->display("index.tpl"); これでindex.tplで出力すると日本語部分が「?????」になってしまいます。 何か設定がいるんでしょうか??

    • ベストアンサー
    • PHP
  • tplを読みに行けません。

    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 どこを間違えているのでしょうか。

    • ベストアンサー
    • PHP

専門家に質問してみよう