Home  >  Article  >  Backend Development  >  Talk about configuration, use Smarty technology_PHP tutorial

Talk about configuration, use Smarty technology_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:58:08695browse

Smarty technology is the essence of PHP. As the PHP version gradually improves, many of the original methods may be too outdated. Below I will talk about how to configure the latest PHP5.1.1 version.

The following is step by step, please note:

1: Download the template library file from the official website : http://smarty.php.net/download.php

After downloading, unzip it, and you will see a folder, it is smarty.x.x, open it, there is a libs folder inside, ok, note that this thing is what we want. Under the website directory, for example, my php website
IIS is under d:/web/web/php on the physical hard disk. Create a folder test under this folder, and then copy the libs folder just mentioned Under the test folder.{ * Please see the comments at the end of this article TIPS1}
3: Create 4 more folders under the test folder;

cache configs templates
templates_c


4: Create file text.htm:


Copy code

The code is as follows :
< ;title><{$title}>


<{$content}>


is saved under the templates directory.
5: Then create the file template configuration file: config.php


Copy code
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 = '}>';
?>

is saved in the main directory, which is under test.
6: Create a new file test.php file in test, enter:


Copy code
The code is as follows: require "config.php"; $tpl-> ;assign("title", "The test was successful, this is the title");
$tpl->assign("content", "This is the content");
$tpl->display(' test.htm');
?>

7: Testing test.php in the browser shows:

This is the content

Congratulations, the configuration is successful. Otherwise, it fails, check again to see if it is as I said.

Tips1: In order to use Smarty technology globally on the website, we can modify PHP.inc inside


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


changed to:
------------------->
; Windows: "path1;path2"
include_path = ".;c:phpincludes;d:webwebphplibs"
When using templates, use them in the same way as before, do not
include "../ libs/Smarty.class.php";
Just use it directly.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317627.htmlTechArticleSmarty technology is the essence of PHP. As the PHP version gradually improves, many of the original methods may be too outdated. , below I will talk about how to configure the latest PHP5.1.1 version....
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Smarty combined with Ajax to implement a non-refresh guestbook example_PHP tutorialNext article:Smarty combined with Ajax to implement a non-refresh guestbook example_PHP tutorial

Related articles

See more