• 締切済み

smartyのdifineについて

表示するファイルにdefineにてパスを設定すると正常に 表示されるのですが管理が面倒なので別のファイルに defineにてパスを設定するとエラーになってしまいます。 具体的には以下のソースです。 ---Smarty/libs/path.php--- define ('SMARTY_LIBS_DIR', 'C:/Program Files/xampp/htdocs/Smarty/libs/'); ---Smarty/libs/MySmarty.class.php--- require_once dirname(__FILE__) . '/Smarty.class.php'; require_once dirname(__FILE__) . '/path.php'; ---Smarty/index.php--- require_once SMARTY_LIBS_DIR . 'MySmarty.class.php'; 調べてみたのですが表示するファイルに指定する方法しか みつからなかったのですが別ファイルから指定する事は 無理なのでしょうか?

noname#65793
noname#65793
  • PHP
  • 回答数1
  • ありがとう数2

みんなの回答

  • livrekun
  • ベストアンサー率47% (9/19)
回答No.1

一番はじめに require するファイルは Smarty/index.php ではないですか? path.phpを読み込む前に SMARTY_LIBS_DIR を使用しているため、未定義の定数なので、そのままの文字列で出力されてしまいます。 ---Smarty/index.php--- define ('SMARTY_LIBS_DIR', 'C:/Program Files/xampp/htdocs/Smarty/libs/'); require_once SMARTY_LIBS_DIR . 'MySmarty.class.php'; ではいけないのでしょうか? また定数でパスを指定してあげているのなら ---Smarty/libs/MySmarty.class.php--- require_once SMARTY_LIBS_DIR . '/Smarty.class.php'; の方が良いです。

関連するQ&A

  • 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
  • xserver Smarty PHP+MySQL

    xserver Smarty PHP+MySQL xserver(レンタルサーバー)でSmartyのtplが読み込まれません。 Xserver(レンタルサーバー)環境 MySQL5 バージョン:5.0.77 MySQL5 ホスト名:xxx.xserver.jp PHP Version 5.3.3 include_path .:/usr/share/php53/pear :/usr/share/php Xserver PHP関連の仕様一覧 PEARインストール済み <インストール済みライブラリ> ・Archive_Tar ・Auth ・Console_Getopt ・DB ・HTML_Common ・HTML_QuickForm ・HTTP ・HTTP_Header ・HTTP_Download ・Mail ・Net_SMTP ・Net_Socket ・Pager ・PEAR ・XML_Parser ・XML_RPC ・Structures_Grap データベースは同じくXserverに設置されているphpmyadmin(MySQL5)で作成しました。 /xxx.xsrv.jp/内に 【php_libs】   [config]     ・config.inc.php   [module]     ・build_screen.inc.php     ・menu.inc.php     ・MYDB.inc.php     ・sub.inc.php       [smarty]     ・cache     ・configs     ・libs     ・templates     ・templates_c 【public_html(DocumentRoot)】   ・testsmarty.php   ・testsmarty.tpl を置いています。 以下のコードでエラーがでます。 Warning: Smarty error: unable to read resource: "testsmarty.tpl" in /home/xxx/xxx.xsrv.jp/php_libs/smarty/libs/Smarty.class.php on line 1088 どこが間違っているのか教えて下さい。 ●testsmarty.php <?php $documentroot = dirname( __FILE__) . '/'; require_once $documentroot . '../php_libs/config/config.inc.php'; require_once( _SMARTY_LIBS_DIR . "Smarty.class.php"); $smarty = new Smarty; $smarty->template_dir = _SMARTY_TEMPLATES_DIR; $smarty->compile_dir = _SMARTY_TEMPLATES_C_DIR; $smarty->config_dir = _SMARTY_CONFIG_DIR; $smarty->cache_dir = _SMARTY_CACHE_DIR; $smarty->assign("title", "タイトル名"); $file = 'testsmarty.tpl'; $smarty->display($file); ?> ●testsmarty.tpl {$title} ●config.inc.php <?php //---------------------------------------------------- // デバッグ表示 true / デバッグ表示オフfalse //---------------------------------------------------- // define("_DEBUG_MODE", true); define("_DEBUG_MODE", false); //---------------------------------------------------- // データベース関連 //---------------------------------------------------- define("_DB_USER", "xxx_sample"); define("_DB_PASS", "password"); define("_DB_HOST", "tcp+xxx.xserver.jp"); define("_DB_NAME", "xxx_sampledb"); define("_DB_TYPE", "mysqli"); define("_DSN", _DB_TYPE . '://' . _DB_USER . ':' . _DB_PASS . '@' . _DB_HOST . '/' . _DB_NAME); //---------------------------------------------------- // 認証関連 //---------------------------------------------------- // 会員認証に使うテーブル名 define("_DB_MEMBER_TB", "m_member"); // 管理者認証に使うテーブル名 define("_DB_SYSTEM_TB", "m_system"); // ユーザー名を格納するカラム名 define("_DB_USERNAMECOL", "username"); // パスワードを格納するカラム名 define("_DB_PASSWORDCOL", "password"); //---------------------------------------------------- // 会員・管理者 処理分岐用 //---------------------------------------------------- // 会員用フラッグ define("_MEMBER_FLG", false); // 管理者フラッグ define("_SYSTEM_FLG", true); //---------------------------------------------------- // セッション名 //---------------------------------------------------- // 会員用セッション名 define("_MEMBER_SESSNAME", "PHPSESSION_MEMBER"); // 管理者用セッション名 define("_SYSTEM_SESSNAME", "PHPSESSION_SYSTEM"); //---------------------------------------------------- // ファイル設置ディレクトリ //---------------------------------------------------- //$smarty->○○○を使わない場合下記で表示されました。 define( "_PHP_LIBS_DIR", "/home/xxx/xxx.xsrv.jp/php_libs/"); // 設定ファイル define( "_CONFIG_DIR", _PHP_LIBS_DIR . "config/"); // 機能ファイル define( "_MODULE_DIR", _PHP_LIBS_DIR . "module/"); //---------------------------------------------------- // Smarty関連設定 //---------------------------------------------------- // Smartyのlibsディレクトリ define( "_SMARTY_LIBS_DIR", _PHP_LIBS_DIR . "smarty/libs/"); // Smartyのテンプレートファイルを保存したディレクトリ define( "_SMARTY_TEMPLATES_DIR", _PHP_LIBS_DIR . "smarty/templates/"); // Smartyのlibsディレクトリ Webサーバから書き込めるようにします。、 define( "_SMARTY_TEMPLATES_C_DIR", _PHP_LIBS_DIR . "smarty/templates_c/"); // Smartyのlibsディレクトリ define( "_SMARTY_CONFIG_DIR", _PHP_LIBS_DIR . "smarty/configs/"); // Smartyのlibsディレクトリ Webサーバから書き込めるようにします。、 define( "_SMARTY_CACHE_DIR", _PHP_LIBS_DIR . "smarty/cache/"); ?>

    • 締切済み
    • PHP
  • さくらにsmartyをセットアップする

    http://www.mogutan-blog.com/?eid=283 さくらサーバーと格闘しています。 上記ブログやその他ブログを見ながらパスは通りましたが、やりたい方法とちがうので改めてこちらでお聞きします。 私の方法 1.smartyをwww以下にアップ 2.アップしたフォルダをlibsと改名 3.index.phpでrequire_once '../libs/smarty/Smarty.class.php'; としてokでした。 しかし、php.iniを使って、 require_once './Smarty.class.php'; とパスを編集するには、php.iniをどのように書けばよろしいでしょうか? 現在は、include_path=".:/home/アカウント名/libs/" としており、どのように書けばパスが通るでしょうか? ちなみに簡略フォルダー展開ですが、 ルート ├ libs(smarty)- Smarty - Smarty.class.php ├ php.ini ├ www ┬ index.php     

    • ベストアンサー
    • 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の設定 include?path以下の設定がわからない

    独学でPHPを学んでいます。 PHPの基本はひととおり理解はできました。 開発環境・最新のXAMPP導入。 windows、OSはVISTA smartyをインストールしましたが、その設定につまずいています。 Smarty.class.phpが存在するパス(D:\xampp\libs)をphp.iniファイル447行目を下記のように設定しましたが、うまくいきません include_path=D:\xampp\libs\ xamppフォルダの下にlibsフォルダを入れたので上のパス指定で問題ないと思うのですが、どこが間違っているのでしょうか。 ちなみに、libs以下の\も不要だろうと思い、消したりして試してみましたが、結果は同じ。下記のように表示がなされます。 Warning: require_once(local/xampp/libs/Smarty.class.php) [function.require-once]: failed to open stream: No such file or directory in D:\xampp\htdocs\lesson\smarty1.php on line 3 Fatal error: require_once() [function.require]: Failed opening required 'local/xampp/libs/Smarty.class.php' (include_path='.;D:\xampp\php\pear\') in D:\xampp\htdocs\lesson\smarty1.php on line 3 上の文章ですが、3行目後半”Smarty.class.php' (include_path='.;D:\xampp\php\pear\')”の部分ですが、php.iniからinclude_pathを変更したりしているのですが、一向に表示が変わりません。 もしかしたらphp.iniファイルは二つあったりするのでしょうか。 php.iniのファイルはPHPフォルダに入っているものでよろしいですよね? もちろんアパッチは再起動させています。 なのにできません・ あと、ロジックファイルの require _once()の()内はSmarty.class.phpだけでもよろしいのでしょうか。 もう悩みすぎて頭がおかしくなりそうですね。 ちなみにsmartyがなくても、アプリケーション開発に支障はありませんでしょうか。 あくまで個人で趣味の範囲でアプリケーションを作成したいと感じています。

    • ベストアンサー
    • PHP
  • PHP4でのSmarty派生クラスの定義について

    こんにちはよろしくお願いします。 PHP4でSmarty派生クラスを定義する方法を教えてください。 PHP5のサンプルコードで次のようなものがありました。 PHP4では,「private」が使えないらしいとか,「__construct」ではなくてクラス名がコンストラクタ名になるとかでうまくいかないようです。どのように修正すればよいのでしょうか? また,「__destruct」はどのようにすれば良いのでしょうか?コンストラクタ名とデストラクタ名が同じでよいのでしょうか? よろしくお願いします。 <?php require_once("DB.php"); require_once("Smarty/libs/Smarty.class.php"); class MySmarty extends Smarty { private $_db; public function __construct() { $this->Smarty(); $this->template_dir="../templates"; $this->compile_dir="../templates_c"; $this->_db=DB::connect("sqlite://localhost/samples.db"); } public function __destruct() { $this->_db->disconnect(); } public function getDb() {return $this->_db;} } ?>

    • ベストアンサー
    • PHP
  • 呼び出し先にさらに呼び出しがある場合について

    PHPバージョン5.2.4を使っています。 index.phpからdir1ディレクトリにあるfile1.phpをrequireして使いたいのですが、 file1.phpもdir1ディレクトリにあるfile2.phpをrequireしているので 次のような呼び出し方ならうまく作動するのですが、 [index.php] define('DIR', realpath(dirname(__FILE__))); require_once 'dir1/file1.php'; [dir1/file1.php] require_once DIR.'/file1.php'; [dir1/file2.php] print "file2表示"; 次のようにindex.phpをdir1ディレクトリに移動させて実行すると file1.phpのrequireでエラーが出てしまいます。 [dir1/index.php] define('DIR', realpath(dirname(__FILE__))); require_once 'dir1/file1.php'; このような呼び出し先の中にさらに別の呼び出しがある場合は どのように記述すればindex.php(実行するファイル)を 別のどんな場所に移動させても作動させることができるのでしょうか?

    • ベストアンサー
    • PHP
  • define でのルートディレクトリの定義について・・・。パスが納得できません。

    宜しくお願いします。 Smarty を使用して PHPを勉強しています。 Smartyのデフォルトを変更しようと、 「MySmarty」として新規にクラスを作成しました。 ソースの先頭で、 define("ROOT_DIR",$_SERVER['DOCUMENT_ROOT']."/.."); として、ROOT_DIRにルートディレクトリまでのパスを記憶させています。 全ソースは下記をごらんくらさい。 そこで、  define("ROOT_DIR",$_SERVER['DOCUMENT_ROOT']."/.."); にある、最後の ."/.."); が納得いきません。。。 最初の . ピリオドは連結のためのものだとわかりますが、 あとの/.. はディレクトリの階層をあげる指示ですよね? てなると、クラスの定義のなかで使用するルートディレクトリへのパス が、 おかしく思えてきます。書籍の通りにやっているので、 この通りにやるとうまくいっていますが、自分的になっとくがいかなく・・。 ソースは下記のようになってます。 特に $this->template_dir  のテンプレートディレクトリへのパスを 再設定しているところですが、 ROOT_DIR."/templates" ということは、ルート/../templates  となりますよね? 作業フォルダの図はこの通りです。↓ C:\xampp   |   libs     |-MySmarty.class.php (下記のソースファイル)   |   |   templates       |-input.tpl   |  templates_c <省略> なんとなくですが、ルート/../templates  ではなくて、 ルート/templates なようなきがします。 わかりにくい説明だったかもしてませんが、何卒宜しくお願いいたします。 ______________________________ define("ROOT_DIR",$_SERVER['DOCUMENT_ROOT']."/.."); require_once("Smarty.class.php"); class MySmarty extends Smarty { function MySmarty (){ $this->template_dir = ROOT_DIR."/templates"; $this->compile_dir = ROOT_DIR."/templates_c"; $this->left_delimiter = "{{"; $this->right_delimiter = "}}"; $this->default_modifiers = array('escape'); $this->Smarty(); } } ____________________________

    • 締切済み
    • PHP
  • Smartyの設置について教えてください。

    お名前.COMにて提供しているVPSサーバプランについてですが、どなたかSmartyを設置された方いらっしゃいますか? いつもの通りユーザ階層にSmartyフォルダを設置し、一通りの事を行って、いざアクセスするもページが真っ白で表示されません。 エラーログを見ても普通にSmarty.classには到達しているようで、何が原因なのかわかりません(泣) てすとで通常のPHPページを作成し、現在の日時を表示するよう書き込んでアップしてみましたところ、普通に表示されるので普通にPHPは使えるんだなって感じです。 では、なぜSmartyだけうまく表示できないのでしょうか? 恐らく私の基本的なミスが原因だと思いますが、一応どなたか設置経験のある方がいましたら、設置内容を改めて教えていただければと思います。 どうぞ、宜しくお願いします。 ちなみに設置階層は下記の通りです。 /httpdocs/Smarty/libs/Smarty.class.php /httpdocs/data/cache /httpdocs/data/configs /httpdocs/data/templates /httpdocs/data/templates_c また、トップにあたるindex.phpの中は以下の通りです。 <?php require_once('./Smarty/libs/Smarty.class.php'); $smarty = new Smarty(); $smarty->template_dir = './data/templates/'; $smarty->compile_dir = './data/templates_c/'; $smarty->config_dir = './data/configs/'; $smarty->cache_dir = './data/cache/'; $smarty->display('index.tpl'); ?> アドバイスで構いませんので宜しくお願いします。

    • 締切済み
    • PHP

専門家に質問してみよう