最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > php教程

PHP教程:配置smarty开发环境

日期:05-04    来源:中国设计秀    作者:cnwebshow.com

提示:配置smarty开发环境.mb5中国设计秀

 mb5中国设计秀

首先到 http://www.smarty.net 上下载最新的smarty模板引擎,解压Smarty-2.6.26.zip,改名Smarty-2.6.26目录为smarty。mb5中国设计秀

拷贝smarty目录到你希望的目录 D:xamppxamppsmarty。mb5中国设计秀

在php.ini的include_path加入smarty库目录,如下:mb5中国设计秀

include_path = “.;D:xamppxamppphpPEAR;D:xamppxamppsmartylibs”mb5中国设计秀

在你的php项目目录新建两个子目录放配置文件和模板:config 和templatesmb5中国设计秀

D:xamppxampphtdocsconfigmb5中国设计秀

D:xamppxampphtdocstemplatesmb5中国设计秀

smarty项目目录新建两个目录cache和templates_c存放缓存和编译过的模板:mb5中国设计秀

D:xamppxamppsmartycachemb5中国设计秀

D:xamppxamppsmartytemplates_cmb5中国设计秀

在需要调用smarty库的php文件中写入代码:mb5中国设计秀

1mb5中国设计秀
2mb5中国设计秀
3mb5中国设计秀
4mb5中国设计秀
5mb5中国设计秀
6mb5中国设计秀
7mb5中国设计秀
8mb5中国设计秀
9mb5中国设计秀
10mb5中国设计秀
11mb5中国设计秀
 
//this is D:xamppxampphtdocsindex.phpmb5中国设计秀
//load smarty librarymb5中国设计秀
require('Smarty.class.php');mb5中国设计秀
mb5中国设计秀
$smarty=new Smarty();mb5中国设计秀
$smarty->template_dir='d:/xampp/xampp/htdocs/templates'; //指定模板存放目录mb5中国设计秀
$smarty->config_dir='d:/xampp/xampp/htdocs/config';//指定配置文件目录mb5中国设计秀
$smarty->cache_dir='d:/xampp/xampp/smarty/cache';//指定缓存目录mb5中国设计秀
$smarty->compile_dir='d:/xampp/xampp/smarty/templates_c';//指定编译后的模板目录mb5中国设计秀
$smarty->assign('name','fish boy!');mb5中国设计秀
$smarty->display('index.tpl');

再新建一个D:xamppxampphtdocstemplatesindex.tpl文件mb5中国设计秀

1mb5中国设计秀
2mb5中国设计秀
3mb5中国设计秀
4mb5中国设计秀
5mb5中国设计秀
6mb5中国设计秀
7mb5中国设计秀
8mb5中国设计秀
9mb5中国设计秀
10mb5中国设计秀
 
<html>mb5中国设计秀
<head><title>hello,{$name}!</title>mb5中国设计秀
<script language="javascript" type="text/javascript">mb5中国设计秀
    alert('{$name}');mb5中国设计秀
</script>mb5中国设计秀
</head>mb5中国设计秀
<body>mb5中国设计秀
hello,{$name}!mb5中国设计秀
</body>mb5中国设计秀
</html>

打开http://localhost/index.php 应该会弹出fish boy!警告,然后内容为hello,fish boy!!的页面。mb5中国设计秀
我们可以改进一下,不可能每次需要smarty写这么多配置代码吧。mb5中国设计秀
新建文件 D:xamppxampphtdocssmarty_connect.phpmb5中国设计秀

1mb5中国设计秀
2mb5中国设计秀
3mb5中国设计秀
4mb5中国设计秀
5mb5中国设计秀
6mb5中国设计秀
7mb5中国设计秀
8mb5中国设计秀
9mb5中国设计秀
10mb5中国设计秀
11mb5中国设计秀
 
//load smarty librarymb5中国设计秀
require('Smarty.class.php');mb5中国设计秀
class smarty_connect extends Smartymb5中国设计秀
{   function smarty_connect()mb5中国设计秀
    {//每次构造自动调用本函数mb5中国设计秀
        $this->template_dir='d:/xampp/xampp/htdocs/templates';mb5中国设计秀
        $this->config_dir='d:/xampp/xampp/htdocs/config';mb5中国设计秀
        $this->cache_dir='d:/xampp/xampp/smarty/cache';mb5中国设计秀
        $this->compile_dir='d:/xampp/xampp/smarty/templates_c';mb5中国设计秀
    }mb5中国设计秀
}

D:xamppxampphtdocsindex.php改为:mb5中国设计秀

1mb5中国设计秀
2mb5中国设计秀
3mb5中国设计秀
4mb5中国设计秀
 
    require('smarty_connect.php');mb5中国设计秀
    $smt=new smarty_connect;mb5中国设计秀
    $smt->assign('name','fish boy!');mb5中国设计秀
    $smt->display('index.tpl');

index.tpl文件不变,打开localhost/index.php,出现了同样的输出。mb5中国设计秀

 
本文引用地址:/bc/article_65316.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明