PHP之smarty框架代码使用流程

版权声明:本文为郝云原创文章,未经郝云允许不得转载。 https://blog.csdn.net/haoyunyun888/article/details/82389387

Smarty使用7步走

1)复制libs里边文件夹到项目目录www中,并改名为smarty

2)创建文件夹templates (html静态页面)

3)  建立index.PHP文件

4)在php页面中引入smarty3入口文件   include  smarty.class.php;

5)创建smarty对象    $smarty=new Smarty();

6)通过assign方法分配变量到模板文件  assign()

7)通过display方法显示输出模板内容    display()

代码实现:

<?php
header("content-type:text/html;charset=utf-8");
// +----------------------------------------------------------------------
// |授课名称:PHP之smarty代码实现
// +----------------------------------------------------------------------
// | 时间:2018年9月4日20:00:04
// +----------------------------------------------------------------------
// | Author: Mr.hao 博客地址:http://blog.csdn.net/haoyunyun888
// +----------------------------------------------------------------------
//引入文件
include "Smarty.class.php";//类
$smarty=new Smarty();//实例化对象
$smarty->assign("username","师梓健");//赋值
$smarty->assign("sex","男");//赋值
$smarty->assign("address","山西临汾");//赋值
$smarty->display('aa.html');//显示

目录结构:

猜你喜欢

转载自blog.csdn.net/haoyunyun888/article/details/82389387