smarty

1.smarty的特点

Smarty是PHP的一个引擎模板,可以更好的进行逻辑与显示的分离,即我们常说的MVC,这个引擎的作用就是将C分离出来

2.smarty下载 :  https://www.smarty.net/

3.smarty的安装

Include / include_once:如果引入的文件不存在,试图继续往下执行,报一个warning

Require /require_once:如果引入的文件不存在,报false error,不再继续记性

4.smarty的使用

使用步骤:

创建相应的文件夹,一般在smarty的解压目录下,创建一个templates目录,用于存放模板,创建一个templates_c,作为编译目录。

在创建的目录的同级目录中,新建一个php文件,如index.php

<?php

include './smarty-3.1.30/libs/Smarty.class.php';

//定义smarty所使用的文件目录
define('SMARTY_ROOT','./');
$smarty=new Smarty();

//指定模板文件所在路径
$smarty->template_dir=SMARTY_ROOT . '/template';

//指定模板编译后的文件所在路径
$smarty->compile_dir=SMARTY_ROOT . 'template_c';

//想模板传递变量
$smarty->assign('name','张三');

//指定模板文件显示
$smarty->display('index.tpl');

编写模板文件

在complates目录创建一个demo.tpl文件。

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<h3>{$name}</h3>
</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值