A joke about configuration, using Smarty Technology

Source: Internet
Author: User
Tags php website

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:
Copy codeThe Code is as follows: <Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> <{$ title}> </title>
</Head>
<Body>
<{$ Content}>
</Body>
</Html>
Save it in the templates directory.
5: create a file template configuration file: config. php
Copy codeThe Code is as follows: <? Php
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:
Copy codeThe Code is as follows: <? Php
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
<B>

Windows: "path1; path2"
Include_path = ".; c: phpincludes"

</B>
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.