选择显示字体大小

[php]配置,使用smarty技术

特别声明:其他网站禁止转载

相关知识:

1、[php]配置,链接access数据库
2、模板引擎smarty深入浅出介绍  

smarty技术是php的精髓所在,随着php版本的逐渐提高,原来的很多方法也许太过时了,下面我就针对最新的php5.1.1版本的使用,配置说说如何配置。

下面是一步步的来的,请注意:

1、在官方下载模板库文件: http://smarty.php.net/download.php

下载了就解压,看见一个文件夹了,是个 smarty.x.x,打开,里面有个libs 文件夹,ok,注意这个东西就是我们要的。

2、在你的网站目录下面,比方我的php网站iis在物理硬盘的 d:/web/web/php下面,在这个文件夹下面建立:一个文件夹 test,然后我们把刚提到的 libs文件夹复制test 文件夹下面。{ * 请看本文最后的注释 tips1}

3、在test 文件夹下面再建立4个文件夹:
cache
configs
templates
templates_c

4、建立文件 text.htm:

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title><{$title}></title>
</head>
<body>
<{$content}>
</body>
</html>

保存在 templates 目录下面。

5、然后建立文件模板配置文件: config.php

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

保存在主目录也就是 test下面。

6、在test新建文件test.php文件,输入:

<?php
    require "config.php";
    $tpl->assign("title", "测试成功了,这是标题");
    $tpl->assign("content", "这是内容");
    $tpl->display('test.htm');
?>

7、在浏览器测试test.php显示为:

这是内容

恭喜,配置成功.否则,失败,再检查是不是按照我说的来的。

tips1 :为了能在网站全局使用smarty技术,我们可以修改php.inc里面的

; windows: "\path1;\path2"
include_path = ".;c:\php\includes"

改为:

; windows: "\path1;\path2"
include_path = ".;c:\php\includes;d:\web\web\php\libs"

使用模板的时候,像前面一样的方式使用,不要:

include "../libs/smarty.class.php";

直接使用就行了的。

经典论坛讨论帖:
http://www.blueidea.com/bbs/newsdetail.asp?id=2405738


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons