• 締切済み

smartyについて

smartyについて 環境は、windows /php-5 / smarty-2.6.17です。 以下の2つエラーが出てどう対処すればいいか困っています。 【1つめ】 Fatal error: Smarty error: [in **.tpl line 10]: syntax error: unrecognized tag: 文--> 【2つめ】 {$errmsg (Smarty_Compiler.class.php, line 446) in C:\xampp\php\PEAR\Smarty\libs\Smarty.class.php on line 1095 【ソース】 呼び先PGは、 $this->smarty->assign("errmsg","ニックネーム"); $this->smarty->display("**.tpl"); テンプレートでは、 <tr id="" class=""> <td id="" class=""><font color="#ff0000">{$errmsg}を入力してください。</font></td> </tr> よろしくお願いいたします。

noname#58128
noname#58128
  • PHP
  • 回答数3
  • ありがとう数3

みんなの回答

回答No.3

内部エンコーディング、PHPスクリプトの文字コード、テンプレートの文字コードを 確認して下さい。 エラーで発生している文字をS-JISとし、EUC-JPで表示した場合は以下になります。 <!--i"・・・{赴+-> <tr id="" class=""><td id="" class="">燕鵜v隊鋲s"縲・・・蛟酪乱Mボタンり・k"逐・準・・B</td></tr> <input type="text" name="Answer1" size="32" maxlength="30" value="{$Answer1}"> UTF-8で表示した場合は以下になります。 <!--{--> <tr id="" class=""><td id="" class="">L̓eł낵ΑM{^ĂB</td></tr> <input type="text" name="Answer1" size="32" maxlength="30" value="{$Answer1}"> 文字コード周りの環境が上手くいってないせいで、Smartyがテンプレートの分析を 行う時点で、ある文字列が「{」と認識され、Smartyの文法が間違っている と怒られている可能性が極めて高いと思われます。

noname#58128
質問者

お礼

ありがとうございます!!

  • yexob328
  • ベストアンサー率25% (1/4)
回答No.2

文字がエラーになっていたら {literal}エラーになっている文字{/literal} と、囲むとよいかもしれません。

noname#58128
質問者

お礼

ありがとうございます!!

回答No.1

テンプレートを削除しながら確認していって、どれが問題で 発生しているか確認して下さい。

noname#58128
質問者

お礼

ありがとうございます。 エラー箇所うを特定いたします!

noname#58128
質問者

補足

調べたところ、テンプレートに書かれている、文字に反応していました。箇所ありました。 【1つめ】 PG:<!--ここから本文-->    エラー文字:本 【2つめ】 PG:<tr id="" class=""><td id="" class="">下記の内容でよろしければ送信ボタンを押してください。</td></tr>   エラー文字:ボ 【3つめ】 PG:<input type="text" name="Answer1" size="32" maxlength="30" value="{$Answer1}">  エラー文字:"{$Answer1}" 3つめはどうしても使用したいのですがどのようにすればいいのでしょうか。

関連するQ&A

  • smartyについて

    smartyを勉強中です。 市販本のサンプルアプリは、うまく実行できました。 環境は、windows /php-5 / smarty-2.6.17 サンプルを真似して、少し修正して、実行すると、下記エラーが出ます。 Fatal error: Smarty error: [in fra_disp.tpl line 13]: syntax error: unrecognized tag: frag.rec_ctl (Smarty_Compiler.class.php, line 446) ソースをじっくり見てますが、サンプルと何が違うか分かりません。こんな質問で申し訳ありませんが、何かヒントいただけませんか。 ちなみに、呼び元pgでは、 $o_smarty->assign("frags",$data); $o_smarty->display("fra_disp.tpl"); また、テンプレートでは、 {foreach from=$frags item="frag"} <tr> <td>{frag.rec_ctl}</td> とコーディングしてます。

    • ベストアンサー
    • PHP
  • Smartyのエラーが2つずつ出ます

    PHP5+Smartyでサイトを作っています。 「$smarty->display("hoge.tpl");」としてテンプレートファイルを呼び出します。 そのテンプレートファイル「hoge.tpl」が存在しない時に、以下のエラー文が必ず2つ表示されます。 Warning: Smarty error: unable to read resource: "hoge.tpl" in /root/.../smarty/Smarty.class.php on line 1092 一度しか呼び出していないのにエラーが2つ表示されるので、コードの記述ミスかと考えたのですがわかりませんでした。 テンプレートファイルがある場合は、テンプレートが二度呼び出されることはありません。 エラー文にある1092行目からコードを追って見たのですがわかりませんでした。 どうすればエラー表示を1つにできるのでしょうか? 宜しくお願いします。

    • 締切済み
    • PHP
  • Smartyでテンプレートが読み込めない

    下記のソースを実行すると、テンプレートが読み込めずエラーになってしまいます。 うーん、何故なのか分からず困っております。 phpのバージョンは4.4.6なのですが、Ver5以降でないとサポートされないのでしょうか。 [source] <?php require_once("Smarty.class.php"); class MySmarty extends Smarty { function _MySmarty() { $this->Smarty(); $this->template_dir="../templates"; $this->compile_dir="../templates_c"; } } $o_smarty=new MySmarty(); $o_smarty->display("hello.tpl"); ?> [error message] Warning: Smarty error: unable to read resource: "hello.tpl"

    • ベストアンサー
    • PHP
  • smartyのforeachの使い方?

    smartyについて教えてください。 mysqlのデータを繰り返し表示させたいのですが Warning: htmlspecialchars() expects parameter 1 to be string, array given in パス modifier.escape.php on line 26 とエラーが出てしまい動作しません。 foreachの使い方がおかしいのかと思いマニュアルをみてみたのですが わかりませんでした。 どうすれば繰り返し表示できるようになるでしょうか? ---php--- $i = 0; $list = array(); while ($col = mysql_fetch_array($res, MYSQL_ASSOC)) { $list[$i]['id'] = $col[id]; $list[$i]['title'] = $col[title]; $list[$i]['main'] = $col[main]; $i++; } $smarty->assign('list', $list); ---tpl--- {foreach item=list from=$list} <tr> <td>{$list.id}</td> <td>{$list.title}</td> <td>{$list.main}</td> <td><a href="hoge.php?id={$list.id}">a</a></td> <td><a href="hoges.php?id={$list.id}">a</a></td> </tr> {/foreach}

    • ベストアンサー
    • PHP
  • Smarty コンバートエラー??

    はじめまして。 PHP初心者です。 テンプレートにオブジェクト配列を渡して、表示させたいのですが、 テンプレートをコンパイルする際にエラーがでてしまいます。 呼び出し元のtest.phpに”echo $objArray[0] -> get_id();”と書くと正常に表示されるのでテンプレートと問題と思うのですが、原因が解らずこまっております。。。 ご指導お願い致します。 ■環境 OS:Fedora 4 php-5.2.0 Smarty-2.6.13 ■ブラウザに表示されるエラー Catchable fatal error: Object of class User could not be converted to string in /home/dev/board/templates_c/%%6D^6D7^6D7C5625%%test.tpl.php on line 3 ■テンプレート(test.tpl) {$users[0] -> get_id()} ■テンプレートの呼び出し元(test.php) require_once("DB.php"); require_once("Smarty/libs/Smarty.class.php"); $o_smarty = new Smarty(); $o_smarty -> template_dir = "../templates"; $o_smarty -> compile_dir = "../templates_c"; $o_smarty -> debugging = TRUE; $db = DB::connect("mysql://*********************"); $objArray = User::getUserInfos($db); echo $objArray[0] -> get_id(); $o_smarty -> assign("users",$objArray); $o_smarty -> display("test.tpl"); class User { private $_id; public function get_id(){return $this -> _id;} public function set_id($_id){$this -> _id = $_id;} public static function getUserInfos($db){ ・・(中略)・・ } return $aryUsr; } }

    • ベストアンサー
    • 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のエラーについて

    お世話になります。 Windows2003でSmartyを使用しています。 Smartyの設定を終えて、index.phpを開くと下記の ようなエラーが出てしまいます。 Warning: Failed opening 'templates_c\%%45^45E^45E480CD%%index.tpl.php' for inclusion (include_path='D:/include') in D:\include\Smarty.class.php on line 1258 Warning: Failed opening 'templates_c\%%D2^D20^D20FCB1F%%debug.tpl.php' for inclusion (include_path='D:/include') in D:\include\Smarty.class.php on line 1925 実際にtemplates_cフォルダを見てみると正常にファイルができています。 よろしくお願いいたします

    • 締切済み
    • PHP
  • Smarty includeでテンプレートを読み込めない

    よろしくお願いします。 まずphpファイルから $smarty->display('111/body.tpl');(*111はディレクトリ名) を呼び出して、さらにbody.tplと同ディレクトリにあるcontents.tplを読み込もうとしています。 はじめのbody.tplは読み込むことができブラウザで表示されるのですが、contents.tplは読み込めず、 Warning: Smarty error: unable to read resource: "contents.tpl" in <絶対パス>/Smarty/Smarty.class.php on line 1095 のエラーが出てしまいます。 ちなみに/111/というディレクトリは、$template_dir以下、$template_dir/111/です。 {include file="contents.tpl"} {include file="file:contents.tpl"} {include file="絶対パス/contents.tpl"} {include file="file:絶対パス/contents.tpl"} など試しましたが、ダメでした。 知恵をお貸しください。よろしくお願いします。

    • ベストアンサー
    • PHP
  • smartyについて

    phpからassignしテンプレートに表示するには問題ないのですがテンプレートでassignし 表示させたく単純に以下のようにしてみましたがエラーになってしまいます。 <{assign var="aaa"value="名前"}> <{$aaa}> ※デリミタ設定は『<{』と『}>』で指定してます エラー内容は以下の通りです。 Fatal error: Smarty error: [in テンプレートファイル line assignしている行]: syntax error: invalid attribute name: '=' (Smarty_Compiler.class.php, line 1550) in ~中略~\Smarty\Smarty.class.php on line 1093 なんとなくではありますが'='が原因のような事はわかるのですが解決できずにおります。 この場合どうすればいいのでしょうか?

    • ベストアンサー
    • 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

専門家に質問してみよう