Joke configuration, using Smarty technology

Source: Internet
Author: User

Smarty Technology is the essence of PHP, as the PHP version of the gradual increase in the original many methods may be too outdated, I will focus on the latest PHP5.1.1 version of the use of configuration said how to configure.
Here is a step-by-step, please note:
1: In the official Download Template Library file: http://smarty.php.net/download.php
Download the decompression, see a folder, is a smarty.x.x, open, there is a libs folder, OK, pay attention to this thing is what we want.
2: Under your website directory, for example, my PHP site IIS under the physical hard disk d:/web/web/php, under this folder to establish: A folder test, and then we have just mentioned the Libs folder under the Test folder copy. {* Please see the note at the end of this article TIPS1}
3: Create 4 more folders under the Test folder;
Cache
Configs
Templates
Templates_c
4: Establish the document text.htm:
[Copy this Code] Code:<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title><{$title}></title>
<body>
<{$content}>
</body>
Saved under the Templates directory.
5: Then create the file template profile: config.php
[Copy this Code] code:<?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 = '}> ';
?>
Saved in the home directory, which is under test.
6: In test new file test.php file, enter:
[Copy this Code] code:<?php
Require "config.php";
$tpl->assign ("title", "Test succeeded, this is the title");
$tpl->assign ("content", "This is contents");
$tpl->display (' test.htm ');
?>
7: In the browser test test.php display as:
This is the content
Congratulations, the configuration was successful. Otherwise, failure, again check is not according to I said.
TIPS1: In order to be able to use Smarty technology on the website, we can modify the php.inc inside
<B>
; Windows: "Path1;path2"
include_path = ".; C:phpincludes "
</B>
To
------------------->
; Windows: "Path1;path2"
include_path = ".; C:phpincludes;d:webwebphplibs "
When using templates, use the same way as before, don't
Include ".. /libs/smarty.class.php ";
The direct use of the line.



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.