電子書籍の厳選無料作品が豊富!

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/");
?>

A 回答 (1件)

あー、最後の方の


// Smartyのテンプレートファイルを保存したディレクトリ
define( "_SMARTY_TEMPLATES_DIR", _PHP_LIBS_DIR . "smarty/templates/");
がおかしいんですが。tplファイルは現状、phpソースと同じディレクトリに置いてるんですよね。
ここで言えば$documentrootじゃないかと。まあ置き場所がここでいいかどうかはさておき。
    • good
    • 0
この回答へのお礼

お返事ありがとうございます。

解決しました。
【public_html(DocumentRoot)】
  ・testsmarty.tplは
  
【php_libs】
  [smarty]
    ・templatesフォルダに置かなければなりませんでした。

当方の書き方が悪かったです。
[smarty]の・cache・configs・libs・templates・templates_cは全てフォルダ(ディレクトリ)名です。

従って下記のように記述すべきでした。
  [smarty]
    [cache]
    [configs]
    [libs]
    [templates]
    [templates_c]

すいませんでした。ありがとうございました。

お礼日時:2012/02/22 21:27

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