Introduction to configuration, using Smarty technology _ PHP Tutorial

Source: Internet
Author: User
Tags php website
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.

....

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.