19.3 install Smarty
Installing Smarty is very simple. First, download the latest stable version at http://smarty.php.net. Run the following command to install Smarty.
(1) decompress the package to a location outside the root directory of the Web document. Ideally, other PHP libraries imported to a specific application should also be placed in this location. For example, in UNIX, this location may be:
In Windows, this location may be:
(2) because the Smarty class library needs to be included in the application, make sure that this location is included in the plude_path configuration instruction of PHP. The class file is Smarty. class. php, which is located in the Smarty directory libs /. For example, the preceding command should be set in UNIX as follows:
In Windows, it should be set:
Of course, you may want to append this path to another path in include_path, because you may want to integrate various libraries into the application in the same way. Remember, after making changes to the PHP configuration file, you need to restart the Web server. In addition, you can use other methods to allow applications to reference the Smarty library. For example, you can simply provide the full absolute path of the class library. Another way is to set a predefined constant named SMARTY_DIR, pointing to the directory of the Smarty class library, and then the class library name starts with this constant. Therefore, even if a configuration makes it impossible to modify the php. ini file, you must be aware that this does not prevent you from using Smarty.
(3) create four directories for storing the Smarty template and configuration file.
Q templates. Place all website templates. The next section will learn more about the template structure.
Q configs. All the special Smarty configuration files used in a specific website. Section 19.6 describes the specific functions of these files.
Q templates_c. Place all templates compiled by Smarty.
Q cache. When the cache feature is enabled, all templates cached by Smarty are placed.
By default, Smarty considers these directories to be in the same directory as the scripts that instantiate the Smarty class, but it is recommended that these directories be placed outside the Web server document root. You can use $ template_dir, $ compile_dir, $ config_dir, and $ cache_dir of Smarty to modify the default behavior. Therefore, you can change its location:
After completing these three steps, you can use Smarty. To make you more interested in this templated engine, let's start with a simple example and then discuss more interesting and useful features.