人気コンテンツ今日: |
SmartyインストールSubmitted by sasaki on 土曜, 2007-09-29 17:24.
Smartyのインストール。基本的には、libsに置く。
■Smartyをダウンロードするダウンロード先: http://smarty.php.net/download.php
■Smartyライブラリファイルを設置する/usr/local/lib/Smarty-バージョン番号 というように設置する。 # tar zxvf Smarty-2.6.18.tar.gz # mv Smarty-2.6.18 /usr/local/lib/
■Smartyの指定方法は2つ
root権限を持っていれば、php.iniを編集できるので今回はこの方法で。 /usr/local/lib/php.iniを編集する。 ;;;;;;;;;;;;;;;;;;;;;;;;; ; Paths and Directories ; ;;;;;;;;;;;;;;;;;;;;;;;;; ; UNIX: "/path1:/path2" include_path = ".:/usr/local/lib/php/PEAR:/usr/share/pear:/usr/local/lib/Smarty-2.6.18/libs/" include_pathに追加する。ディレクトリのスラッシュ / をlibsに付けて指定する。 これでライブラリファイルは正常に設置が完了。
■自分のアプリケーション内にSmarty用のディレクトリをセットアップするSmartyを使用する各アプリケーションごとに4つのディレクトリが必要。
ルートドキュメントの外に設置することが推奨されているので、 /home/foo/public_html/index.php /home/foo/templates/ /home/foo/templates_c/ /home/foo/configs/ /home/foo/cache/ となるようにディレクトリをmkdirコマンドで作成しておく。
templates_c/ と cache/ の2つのディレクトリはApache実行ユーザが「書き込み権限でアクセスする必要」がある。ps aux | grep apache で調べて実行ユーザが apache だとすると、このように設定する。 # chown apache:apache /home/foo/templates_c # chown apache:apache /home/foo/cache # chmod 775 /home/foo/template_c # chmod 775 /home/foo/cache
■テンプレートを設置する試しにテンプレートを作成する。 /home/foo/templates/index.tml
{* Smarty *}
こんにちは、{$name}。ようこそ Smarty へ!
このテンプレートを使った index.php を編集する。 /home/foo/public_html/index.php
<?php
require_once('Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = '/home/foo/templates/';
$smarty->compile_dir = '/home/foo/templates_c/';
$smarty->config_dir = '/home/foo/configs/';
$smarty->cache_dir = '/home/foo/cache/';
$smarty->assign('name', 'Ned');
$smarty->display('index.tpl');
?>
ブラウザからindex.phpにアクセスすると、このように表示されるはず。 こんにちは、Ned。ようこそ Smarty へ!
|
PHPamazon広告英語お勧め教材! 英語の学校でも使っているのですが、1つのストーリーを3分で読めて、内容も面白く、もっと早く出会いたかった本です。 Apple好きで英語も勉強したいならこの一冊! ブログパーツ |