Download and install smarty

Source: Internet
Author: User
Tags php template smarty template

Smarty is a PHP template engine developed by Monte OHRT and Andrei zmievski using the PHP language. It has become a very popular template engine since its development, smarty provides an easy-to-manage and use method to share PHP code from the hmtl code page. The division of labor between programmers and page artists is clearer, greatly improve the development efficiency of the team.

1. To use smarty to go to the official website http://www.smarty.net to download, download completed by the following steps to install:
(1) decompress the downloaded smarty package to a specified location, such as C:/smarty.
(2) because the smarty class library is used in the program, and the smarty class file is the smarty in the libs folder. class. PHP file, so you need to modify the PHP configuration file PHP. INI file: Find the include_path entry and add include_path = ".; c:/smarty/Libs ". Note that multiple paths can be separated by semicolons, because the newly added path will overwrite the preceding path settings.
When referencing the page: require ('smarty. Class. php ');
(3) Another method is to manually set the smarty_dir constant, for example:
Define ('smarty_dir ','/usr/local/lib/PHP/smarty/libs /');
Require (smarty_dir. 'smarty. Class. php ');
(4) Another method is to reference the absolute path of the library file, which is not recommended. The Code is as follows:
Require ('/usr/local/lib/PHP/smarty/libs/smarty. Class. php ');
[Note: The actual installation path is used for reference only.]

2. Configure smarty. When using smarty, you need to create the following four directories to store the smarty template and configuration file:
(1) templates: stores template files
(2) templates_c: stores compiled PHP files
(3) configs: stores configuration files
(4) cache: stores the smarty cache Template
[Note: The templates and templates_c directories must be created. You can create configs and cache as needed, but the directory names must be the four file names and cannot be modified, otherwise, the system will prompt that the file cannot be found.]

In applications, these files can be directly placed in the directory where the PHP file is located. For security reasons, we recommend that you separate these four files from the directory where the PHP file is located and put them in a separate directory, then, declare $ template_dir, $ compile_dir, $ config_dir, and $ cache_dir in the program, for example
Require ('smarty. Class. php ');
$ Smarty = new smarty ();
$ Smarty-> $ template_dir ("/usr/local/lib/PHP/smarty /");
$ Smarty-> $ compile_dir ("/usr/local/lib/PHP/smarty /");
$ Smarty-> $ config_dir ("/usr/local/lib/PHP/smarty /");
$ Smarty-> $ cache_dir ("/usr/local/lib/PHP/smarty /");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.