| ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot |
Basic InstallationInstall the Smarty library files which are in the /libs/ directory of the distribution. These are the PHP files that you SHOULD NOT edit. They are shared among all applications and they only get updated when you upgrade to a new version of Smarty. Smarty uses a PHP constant named SMARTY_DIR which is the system filepath Smarty library directory. Basically, if your application can find the Smarty.class.php file, you do not need to set SMARTY_DIR, Smarty will figure it out on its own. Therefore, if Smarty.class.php is not in your include_path, or you do not supply an absolute path to it in your application, then you must define SMARTY_DIR manually. SMARTY_DIR must include a trailing slash. Here is how you create an instance of Smarty in your PHP scripts: Try running the above script. If you get an error saying the Smarty.class.php file could not be found, you have to do one of the following: Now that the library files are in place, it's time to setup the Smarty directories for your application. Smarty requires four directories which are (by default) named templates, templates_c, configs and cache. Each of these are definable by the Smarty class properties $template_dir, $compile_dir, $config_dir, and $cache_dir respectively. It is highly recommended that you setup a separate set of these directories for each application that will use Smarty. Be sure you know the location of your web server document root. In our example, the document root is "/web/www.mydomain.com/docs/". The Smarty directories are only accessed by the Smarty library and never accessed directly by the web browser. Therefore to avoid any security concerns, it is recommended to place these directories in a directory off the document root. For our installation example, we will be setting up the Smarty environment for a guest book application. We picked an application only for the purpose of a directory naming convention. You can use the same environment for any application, just replace "guestbook" with the name of your app. We'll place our Smarty directories under "/web/www.mydomain.com/smarty/guestbook/". You will need as least one file under your document root, and that is the script accessed by the web browser. We will call our script "index.php", and place it in a subdirectory under the document root called "/guestbook/". It is convenient to setup the web server so that "index.php" can be identified as the default directory index, so if you access "http://www.mydomain.com/guestbook/", the index.php script will be executed without "index.php" in the URL. In Apache you can set this up by adding "index.php" onto the end of your DirectoryIndex setting (separate each entry with a space.) Lets take a look at the file structure so far: Smarty will need write access to the $compile_dir and $cache_dir, so be sure the web server user can write to them. This is usually user "nobody" and group "nobody". For OS X users, the default is user "web" and group "web". If you are using Apache, you can look in your httpd.conf file (usually in "/usr/local/apache/conf/") to see what user and group are being used.
We need to create the index.tpl file that Smarty will load. This will be located in your $template_dir.
Now lets edit index.php. We'll create an instance of Smarty, assign a template variable and display the index.tpl file. In our example environment, "/usr/local/lib/php/Smarty" is in our include_path. Be sure you do the same, or use absolute paths.
Now load the index.php file from your web browser. You should see "Hello, Ned!" You have completed the basic setup for Smarty! |
各種マニュアル:
PHPマニュアル |
PEARマニュアル |
Smarty(英語)マニュアル |
PHP-GTKマニュアル |
「Basic Installation」をGoogle検索
|