Let's talk about the configuration and use the Smarty technology. The Smarty technology is the essence of PHP. with the gradual improvement of PHP version, many of the original methods may be too outdated. next I will talk about how to configure the latest PHP5.1.1 version. the Smarty technology is the essence of PHP. with the gradual improvement of PHP version, many of the original methods may be too outdated. next I will talk about how to configure the latest PHP5.1.1 version.
The following is a step by step. Please note:
1. download the template library file from the official website.: Http://smarty.php.net/download.php
After downloading the file, decompress it and you will see a folder named smarty. x. x. open it and there is a libs folder. OK. Note that this is what we want.
2: Under your website directory, for example, my php websiteIIS is under d:/web/php on the physical hard disk. create a folder named test under this folder. then, copy the folder named libs to the directory named test. {* Please refer to the comment TIPS1 at the end of this article}
3: Create four more folders under the test folder;
Cache
Configs
Templates
Templates_c
4: create a file text.htm:
The code is as follows:
<{$ Title}>
<{$ Content}>
Save it in the templates directory.
5: create a file template configuration file: config. php
The code is as follows:
Include "../libs/Smarty. class. php ";
$ NowPathArray = explode ("test", str_replace ("\", "/", dirname (_ FILE __)));
@ Define ("root_path", $ NowPathArray [0]);
@ Define ('_ SITE_ROOT', root_path. "test ");
$ Tpl = new Smarty ();
$ Tpl-> template_dir = _ SITE_ROOT. "/templates /";
$ Tpl-> compile_dir = _ SITE_ROOT. "/templates_c /";
$ Tpl-> config_dir = _ SITE_ROOT. "/configs /";
$ Tpl-> cache_dir = _ SITE_ROOT. "/cache /";
$ Tpl-> left_delimiter = '<{';
$ Tpl-> right_delimiter = '}> ';
?>
Save it in the main directory named test.
6. create the test. php file in test, and enter:
The code is as follows:
Require "config. php ";
$ Tpl-> assign ("title", "the test is successful. this is the title ");
$ Tpl-> assign ("content", "This is content ");
$ Tpl-> display('test.htm ');
?>
7: test. php in the browser:
This is content
Congratulations, the configuration is successful. Otherwise, the configuration fails and check whether it is as I said.
Tips1: to use Smarty technology globally on the website, we can modify
Windows: "path1; path2"
Include_path = ".; c: phpincludes"
Changed:
------------------->
Windows: "path1; path2"
Include_path = ".; c: phpincludes; d: webwebphplibs"
Use the template in the same way as before. do not
Include "../libs/Smarty. class. php ";
Just use it.
....