• ベストアンサー

Smartyでのエラー

Smartyを使用してみようと思い、displayを使用すると $smarty->display("ファイル名.tpl"); 「Fatal error: Call to a member function display() on a non-object」 と出てしまいます。このエラーはどういう意味なのでしょうか…。

noname#22928
noname#22928
  • PHP
  • 回答数1
  • ありがとう数0

質問者が選んだベストアンサー

  • ベストアンサー
  • tany180sx
  • ベストアンサー率63% (239/379)
回答No.1

$smartyはオブジェクトではないし displayというメソッドも存在しません。 $smarty = new Smarty(); $smarty->display();

関連するQ&A

  • 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
  • ネットで商品購入時に表示されるエラーメッセージについて

    Fatal error: Call to a member function on a non-object ↑のようなメッセージが表示され、ネットでの手続きが不能になってしまいます。このメッセージの意味、対処の方法を教えて頂きたいのですが。 宜しくお願いします。

  • 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 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の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
  • エラーコードの意味を教えてください。

    エラーコード: Call to a member function find() on a non-object in C:\xampp\hairetu2.php on line 29 simple_html_dom.php というファイルを使ってHTMLのソース抜き出しを試みているのですが、 このエラーの意味がgoogleで調べてもそれらしいのがみつからないので ご質問させていただきました。 「対象データがないよ」ってことでしょうか。。。 ご存知の方 ご指摘願います。

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

    今度業務でPHPをやる事になったので手始めにSmartyを使って簡単なアプリケーションを作ってみようと思ったのですが、最初の段階でいきなりつまづいてしましました。 具体的には、サンプルサイトからコピーした以下の様なphp&テンプレートを動かすと決まって次のエラーになります。 【/var/www/html/test/index.php】 <?php require_once('/var/www/smarty/libs/Smarty.class.php'); $smarty = new Smarty; $smarty->assign('name', 'test'); $smarty->display('index.tpl'); ?> 【/var/www/html/test/templates/index.tpl】 <html> <head> <title>User Info</title> </head> <body> 名前:{$name}<br> </body> 【エラー】 Warning: preg_match() [function.preg-match]: Compilation failed: repeated subpattern is too long at offset 18454 in /var/www/smarty/libs/Smarty_Compiler.class.php on line 454 ちなみに環境は以下の通りです。 OS:CentOS5.2 web:apache2.2.3 php:5.1.6 Smarty:2.6.21 同様の基本的なサンプルを他にもいくつか実行しましたが、結果は上記エラーと全く同一のものしか出力されません… 同じ症状が出て対応された方がいらっしゃいましたら回答の程よろしくお願い致します。

    • ベストアンサー
    • 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 コンバートエラー??

    はじめまして。 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

専門家に質問してみよう