Smartyを導入する
Smartyを導入する
0.改訂履歴
1.はじめに
このドキュメントでは,Smarty 2.6.12を導入する手順を説明する. SmartyとはPHPのテンプレートエンジンで,数ある類似エンジンよりも楽天などでも利用されており,大変事例の多い事が特徴らしい.
なお,使用しているOSは,RedHat Linux ES3.0上で稼働しているApache2.0.55,PHP4.1.3である.
2.インストール
[root@uranos2 Download]# wget http://smarty.php.net/do_download.php?download_file=Smart
y-2.6.12.tar.gz
--12:31:16-- http://smarty.php.net/do_download.php?download_file=Smarty-2.6.12.tar.gz
=> `do_download.php?download_file=Smarty-2.6.12.tar.gz'
Resolving smarty.php.net... 128.39.198.38
Connecting to smarty.php.net[128.39.198.38]:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://smarty.php.net/distributions/Smarty-2.6.12.tar.gz [following]
--12:31:19-- http://smarty.php.net/distributions/Smarty-2.6.12.tar.gz
=> `Smarty-2.6.12.tar.gz'
Connecting to smarty.php.net[128.39.198.38]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 144,512 [application/x-gzip]
100%[=====================================================>] 144,512 70.81K/s
12:31:22 (70.66 KB/s) - `Smarty-2.6.12.tar.gz' saved [144,512/144,512]
[root@uranos2 Download]#
|
[root@uranos2 Download]# tar xfz Smarty-2.6.12.tar.gz
[root@uranos2 Download]#
|
[root@uranos2 Download]# ls -la Smarty-2.6.12
total 356
drwxrwxr-x 6 102 wheel 4096 Jan 19 03:53 .
drwxr-xr-x 11 root root 4096 Feb 20 12:36 ..
-rw-rw-r-- 1 102 wheel 370 Feb 22 2003 BUGS
-rw-rw-r-- 1 102 wheel 24389 Feb 8 2001 COPYING.lib
-rw-rw-r-- 1 102 wheel 206853 Jan 16 15:31 ChangeLog
-rw-rw-r-- 1 102 wheel 12740 Apr 12 2003 FAQ
-rw-rw-r-- 1 102 wheel 1408 Aug 26 2003 INSTALL
-rw-rw-r-- 1 102 wheel 44794 Jan 19 03:50 NEWS
-rw-rw-r-- 1 102 wheel 3052 Feb 24 2005 QUICK_START
-rw-rw-r-- 1 102 wheel 3185 Jan 22 2005 README
-rw-rw-r-- 1 102 wheel 18942 Feb 4 2005 RELEASE_NOTES
-rw-rw-r-- 1 102 wheel 421 Dec 11 2003 TODO
drwxrwxr-x 5 102 wheel 4096 Jan 19 03:52 demo
drwxrwxr-x 4 102 wheel 4096 Jan 19 03:52 libs
drwxrwxr-x 2 102 wheel 4096 Jan 19 03:51 misc
drwxrwxr-x 4 102 wheel 4096 Jan 19 03:51 unit_test
[root@uranos2 Download]#
|
[root@uranos2 Download]# ls -la Smarty-2.6.12/libs/
total 204
drwxrwxr-x 4 102 wheel 4096 Jan 19 03:52 .
drwxrwxr-x 6 102 wheel 4096 Jan 19 03:53 ..
-rw-rw-r-- 1 102 wheel 12747 Jan 19 03:51 Config_File.class.php
-rw-rw-r-- 1 102 wheel 63249 Jan 19 03:52 Smarty.class.php
-rw-rw-r-- 1 102 wheel 91400 Jan 19 03:52 Smarty_Compiler.class.php
-rw-rw-r-- 1 102 wheel 5066 Sep 21 2004 debug.tpl
drwxrwxr-x 2 102 wheel 4096 Jan 19 03:51 internals
drwxrwxr-x 2 102 wheel 4096 Jan 19 03:51 plugins
[root@uranos2 Download]#
|
[root@uranos2 Download]# mkdir /usr/local/lib/php/Smarty
[root@uranos2 Download]#
|
[root@uranos2 Download]# cp -r Smarty-2.6.12/libs/* /usr/local/lib/php/Smarty
[root@uranos2 Download]#
|
3.PHPへの登録
- php.iniに追加したSmartyライブラリへのパスを追加する.
[root@uranos2 Download]# locate php.ini
/etc/php.ini
/root/Download/php-4.3.11/pear/tests/php.ini
/root/Download/php-4.3.11/php.ini-recommended
/root/Download/php-4.3.11/php.ini-dist
/usr/local/lib/php.ini
[root@uranos2 Download]# cp /usr/local/lib/php.ini /usr/local/lib/php.ini.20060220before
[root@uranos2 Download]#
|
変更前 |
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "¥path1;¥path2"
;include_path = ".;c:¥php¥includes"
|
変更後 |
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
include_path = ".:/php/includes:/usr/local/lib/php/Smarty"
;
; Windows: "¥path1;¥path2"
;include_path = ".;c:¥php¥includes"
|
[root@uranos2 Download]# /etc/init.d/httpd stop;/etc/init.d/httpd start
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@uranos2 Download]#
|
- phpinfo()によって,include_pathが追加されていることを確認する.
- また,次のようなプログラムを作成して実行することで,Smartyのバージョンなども確認できる.
[root@uranos2 htdocs]# cat smarty.php
<?php
@include('Smarty.class.php');
if (class_exists('Smarty')) {
$smary =& new Smarty;
printf("you can use Smarty(version %s).¥n", $smary->_version);
} else {
echo "you can't use Smarty.¥nplease install Smarty library.";
}
?>
[root@uranos2 htdocs]#
|
- うまく認識されていないときは,次のようなエラーが表示される.