source: branches/comu-ver2/data/module/Smarty/QUICK_START @ 15079

Revision 15079, 3.0 KB checked in by nanasess, 14 years ago (diff)

svn:mime-type application/x-httpd-php; charset=UTF-8 設定

  • Property svn:mime-type set to application/x-httpd-php; charset=UTF-8
Line 
1This is a simple guide to get Smarty setup and running quickly. The online
2documentation includes a very thorough explanation of a Smarty installation.
3This guide is meant to be a quick and painless way of getting Smarty working,
4and nothing more. The guide assumes you are familiar with the UNIX system
5environment. Windows users will need to make adjustments where necessary.
6
7INSTALL SMARTY LIBRARY FILES
8
9Copy the Smarty library files to your system. In our example, we place them in
10/usr/local/lib/php/Smarty/
11
12$> cd YOUR_DOWNLOAD_DIRECTORY
13$> gtar -ztvf Smarty-2.6.7.tar.gz
14$> mkdir /usr/local/lib/php/Smarty
15$> cp -r Smarty-2.6.7/libs/* /usr/local/lib/php/Smarty
16
17You should now have the following file structure:
18
19/usr/local/lib/php/Smarty/
20                          Config_File.class.php
21                          debug.tpl
22                          internals/
23                          plugins/
24                          Smarty.class.php
25                          Smarty_Compiler.class.php
26
27
28SETUP SMARTY DIRECTORIES
29
30You will need four directories setup for Smarty to work. These files are for
31templates, compiled templates, cached templates and config files. You may or
32may not use caching or config files, but it is a good idea to set them up
33anyways. It is also recommended to place them outside of the web server
34document root. The web server PHP user will need write access to the cache and
35compile directories as well.
36
37In our example, the document root is /web/www.domain.com/docs and the
38web server username is "nobody". We will keep our Smarty files under
39/web/www.domain.com/smarty
40
41$> cd /web/www.domain.com
42$> mkdir smarty
43$> mkdir smarty/templates
44$> mkdir smarty/templates_c
45$> mkdir smarty/cache
46$> mkdir smarty/configs
47$> chown nobody:nobody smarty/templates_c
48$> chown nobody:nobody smarty/cache
49$> chmod 775 smarty/templates_c
50$> chmod 775 smarty/cache
51
52
53SETUP SMARTY PHP SCRIPTS
54
55Now we setup our application in the document root:
56
57$> cd /web/www.domain.com/docs
58$> mkdir myapp
59$> cd myapp
60$> vi index.php
61
62Edit the index.php file to look like the following:
63
64<?php
65
66// put full path to Smarty.class.php
67require('/usr/local/lib/php/Smarty/Smarty.class.php');
68$smarty = new Smarty();
69
70$smarty->template_dir = '/web/www.domain.com/smarty/templates';
71$smarty->compile_dir = '/web/www.domain.com/smarty/templates_c';
72$smarty->cache_dir = '/web/www.domain.com/smarty/cache';
73$smarty->config_dir = '/web/www.domain.com/smarty/configs';
74
75$smarty->assign('name', 'Ned');
76$smarty->display('index.tpl');
77
78?>
79
80
81SETUP SMARTY TEMPLATE
82
83$> vi /web/www.domain.com/smarty/templates/index.tpl
84
85Edit the index.tpl file with the following:
86
87<html>
88<head>
89<title>Smarty</title>
90</head>
91<body>
92Hello, {$name}!
93</body>
94</html>
95
96
97
98Now go to your new application through the web browser,
99http://www.domain.com/myapp/index.php in our example. You should see the text
100"Hello Ned!" in your browser.
101
102Once you get this far, you can continue on to the Smarty Crash Course to learn
103a few more simple things, or on to the documentation to learn it all.
Note: See TracBrowser for help on using the repository browser.