UPDATE:2024年11月29日
Smarty3をインストールする!
Smarty3の日本語マニュアル
Smarty3 マニュアル:http://www.smarty.net/docs/ja/
動作環境
Smarty3をダウンロード
基本的なインストール
libs のアップロード
今回アップロードする箇所は、wepicks.net 直下にします。wepicks.net直下に smarty3 という名前のディレクトリを作成し、そこへ libs フォルダと中の全ファイルをアップロードします。
/Smarty3/
libs/
Smarty.class.php
SmartyBC.class.php
debug.tpl
sysplugins/* (すべて)
plugins/* (すべて)
URL
https://wepicks.net/Smarty3/libs/・・・
ディレクトリの作成
libs をアップロードした階層に4つのディレクトリを作成してください。
/Smarty3/
libs/
templates/
templates_c/
configs/
cache/
templates_c と cache ディレクトリのパーミッションを 770 に変更して下さい。
chmod 770 /web/www.example.com/smarty3/templates_c/ chmod 770 /web/www.example.com/smarty3/cache/
ディレクトリのパーミッション(アクセス権限)の確認
各ディレクトリのパーミッション(アクセス権限)の設定が正しいか確認してみましょう。確認するには、testInstall() を使います。
dir-perm-check.php ファイルを作成して以下のコードを記述して下さい。3行目の define で libs への絶対パスを指定します。自分の環境に合わせてサーバーの絶対パスを指定してください。作成したら、libs と同じ階層にアップロードしてください。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <!-- サンプルコード --> <?php //libs ディレクトリへの絶対パスを指定 define('SMARTY_DIR', '/自分の環境/smarty3/libs/'); //ファイルの読み込み require_once(SMARTY_DIR . 'Smarty.class.php'); //Smartyのインスタンスの作成 $smarty = new Smarty(); //ディレクトリのパーミッションを確認 $smarty->testInstall(); ?> |
ファイルをアップロードする場所
/Smarty3/
libs/
templates/
templates_c/
configs/
cache/
dir-perm-check.php
ファイルのアップロードが完了したら、ブラウザから dir-perm-check.php へアクセスしてみて下さい。正常に設置できている場合は以下の表示が出力されます。
Testing template directory…
/自分の環境/smarty3/templates is OK.
Testing compile directory…
/自分の環境/smarty3/templates_c is OK.
Testing plugins directory…
/自分の環境/smarty3/libs/plugins is OK.
Testing cache directory…
/自分の環境/smarty3/cache is OK.
Testing configs directory…
/自分の環境/smarty3/configs is OK.
Testing sysplugin files…
… OK
Testing plugin files…
… OK
Tests complete.
テンプレートファイルの作成
{* Smarty *}
こんにちは、{$name}。ようこそ Smarty へ!
ファイルを作成したら、templates ディレクトリへアップロードして下さい。
/Smarty3/
templates/
index.tpl
テストファイルの作成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <!-- サンプルコード --> <?php //libs ディレクトリへの絶対パスを指定 define('SMARTY_DIR', '/自分の環境/smarty3/libs/'); //ファイルの読み込み require_once(SMARTY_DIR . 'Smarty.class.php'); //Smartyのインスタンスの作成 $smarty = new Smarty(); //テンプレート変数を代入 $smarty->assign('name','TRY PHP !'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <?php //テンプレートを表示 $smarty->display('index.tpl'); ?> </body> </html> |
ファイルを作成したら、libs と同じ階層にファイルをアップロードして下さい。
ファイルをアップロードする場所
/Smarty3/
libs/
templates/
templates_c/
configs/
cache/
dir-perm-check.php
test.php
ブラウザから test.php へアクセスすると以下のように表示されます。
以上で完了です!
タグ(=記事関連ワード)
日付
最終更新日:2024年11月29日


