性格悪い人が優勝

いつもお世話になっております。

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


どう対処すればいいでしょうか。
よろしくご教示お願いいたします。

A 回答 (4件)

Smarty.class.php で SMARTY_DIRは定義されていましたが、class 定義の外に実装されています。



if (!defined('SMARTY_DIR')) {
define('SMARTY_DIR', dirname(__FILE__) . DS);
}

こんな感じ。そうすると
> $this->template_dir = SMARTY_DIR . "templates";

は Smarty.class.php のあるディレクトリの配下に templates ディレクトリがあるようになりますが、問題ありませんか?

PATHがズレているように思うのですが。

この回答への補足

NARHさん、ご回答ありがとうございます。

Smarty.class.php を読み込む前に SMARTY_DIR を設定しました。
define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
require_once 'Smarty.class.php';


それでも同じエラーが表示されてしまいます。
よろしくご教示お願いいたします。

補足日時:2011/02/14 10:41
    • good
    • 0

おそくなってすみません。


見逃していました。

だいぶ時間がたったので、もう解決されているかと思いますが

> define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);

を /Smart/lib/smarty_setup.php に仕込んだとすると

/Smart/lib/templates をサーチ対象にしちゃうので、やっぱりPATHがずれることになりませんか?

(ん?Smart?まぁいいや)

これ自体カスタマイズされたフォルダ構成なのですから、安直に
define('SMARTY_DIR', 'フルパス');で書いちゃっても(設定ファイルを別で設けないかぎりは)、そんなに意味合いは変わらないんじゃないかと。

1つ上の階層みたいなので
define('SMARTY_DIR', dirname( dirname(__FILE__) ). DIRECTORY_SEPARATOR);
とするとか

この回答への補足

NARHさん、度々ご回答ありがとうございます。

いろいろ調べたり、試行錯誤した結果、Smartyを見送ることにしました。
勉強不足だと痛感しております。

再度Smartyは使うはずなので、参考にさせていただきます。
本当にありがとうございました。

補足日時:2011/02/21 10:58
    • good
    • 0

エラーの内容はテンプレートファイルが読み込みできませんよと言っています。



気になったのは、SMARTY_DIR ってどこで定義しているのでしょう?
define している箇所が見当たりませんが?
    • good
    • 0

ん?


> require_once 'Smarty.class.php';
>
> class SmartySetup extends Smarty {

SmartySetup class を定義しておいて

> require_once("../../Smarty/libs/smarty_setup.php");
> $smarty = new Smarty();

それを無視して、わざわざ Smarty のインスタンスをとるのは、何か理由があるのですか?
SmartySetup クラスのコンストラクタで指定している設定が読み込まれないと思います。

パッと見た感じ

$smarty = new SmartySetup();

とするような意図があるように読めますが。

この回答への補足

NARHさん、ご回答ありがとうございます。

ご指摘の通り、
$smarty = new Smarty();
から
$smarty = new SmartySetup();
に変更したのですが、エラーの内容に変化がありません。

忘れていましたが、環境は以下の通りです。
PHP:5.3.5
Smarty:Smarty-3.0.6

よろしくお願いいたします。

補足日時:2011/02/10 17:24
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!