Next let's take a look at the smarty Template installation and configuration tutorial.
1. Download the Smarty package
Download: http://smarty.php tutorial. net from official site
2. Decompress the Smarty package and find a suitable location for storage. after decompression, the folder name may be Smarty. x. x. x, change it to smarty (this is only for future convenience, not required ), then copy the folder containing the Smarty file to a directory (we recommend that you do not place it in your website directory, so that others can access these files through the path, if you have to put it in the website directory, the names of the best directories are somewhat uncommon. These files may not cause security issues even if they are accessed by others, but everything is done just in case ).
In the following content, we assume that your file is stored in d: smarty.
3. Find Your php. ini configuration file (you can run phpinfo () to view the path of this file, but it is usually stored in the system directory) to modify php. add the path of the smarty library file to the initde_path option, for example:
Include_path = ".; d: smartylibs"
Note: php. ini contains two types of include_path, which are used in Unix and windows. You need to modify the values used in windows:
-------------------------------------------------------------
Windows: "path1; path2"
Include_path = ".; c: phpincludes; D: PHPSmartylibs"
--------------------------------------------------------------
4. Restart IIS/APACHE to make the modification take effect.
The restart method is simple. You can simply restart APACHE directly. For IIS, you can run the net stop iiadmin command to disable iis and run the net start w3svc command to start IIS. If it doesn't restart, simply restart the computer.
After setting, you can use include ("Smarty. class. php") in the php file. The statement can be called directly.
5. Create a folder under your website directory with any name. Assume MySmarty:
Then, create two folders, templates and configs, under the MySmarty directory.
After the creation is complete:
(Your Website Directory)/MySmarty/templates (this directory is used to store templates)
(Your Website Directory)/MySmarty/configs (this directory is used to store some configuration information)
6. Create two folders under the MySmarty directory named smarty_cache and smarty_templates_c respectively. Why didn't I create them together? Because this step does not exist in the original official materials, and I found during the configuration process that without these two folders, smarty will not work, I don't know why the official smarty version is different from the latest version. However, if you configure these two directories, Smarty can work smoothly. Therefore, we recommend that you configure it.
7. At this time, you should not forget to set the permissions for the four folders we created from the beginning to now. Of course, it also includes the permissions to store the folder d: smarty, because some systems in the NTFS format have strict permission regulations, after creating your directory, you must have sufficient permissions to allow web programs to access it. In general, systems using NTFS partition format in win2000 and win2003 need to do this. The specific method is to right-click the folder and open the "security" label in "properties, the list of users who can access this directory is listed. If you do not have the web access permission, you need to add the Internet guest account and the IIS process account that starts. If you are in trouble, you can directly add the Everyone user group to allow access by any user.
8. The installation is basically completed at this time. You can test the first simple example:
Create the index. Php file under your website directory, and create the index. tpl file under (website directory)/smarty/templates/. Enter the following code respectively.
Index. php
<? Php
// Load the Smarty Library
Include ("Smarty. class. php ");
$ Smarty = new Smarty;
// The following (your website directory) uses an absolute path, such as d:/intepub/wwwroot
$ Smarty-> template_dir = 'd:/WorkSpace/PHP/MySmarty/templates ';
$ Smarty-> config_dir = 'd:/WorkSpace/PHP/MySmarty/config ';
$ Smarty-> cache_dir = 'd:/WorkSpace/PHP/MySmarty/smarty_cache ';
$ Smarty-> compile_dir = 'd:/WorkSpace/PHP/MySmarty/smarty_templates_c ';
// Required parameter configuration before using Smarty for the above four actions
$ Smarty-> assign ('name', 'Install Smarty ');
$ Smarty-> display ('index. tpl ');
?>
Index. tpl
<Html>
<Body>
Hello, {$ name }!
</Body>
</Html>
9. Now you can finally watch the following masterpiece. Run index. php (of course, it runs on your web server, exactly the same as running a common php file .)
Http: // localhost/index. php
If the following output is displayed, the installation is successful ~~~ Is it easy?
Hello, learn to install Smarty with 17PHP!