当前位置: 首页 > news >正文

PHP之Smarty使用以及框架display和assign原理

一、Smarty的下载

进入Smarty官网下载,复制目录libs目录即可http://www.smarty.net/http://www.smarty.net/

 

 

 二、使用Smarty,创建目录demo,把libs放进去改名为Smarty             
 三、引入Smarty配置,创建目录,index.php文件配置

<?php
include './Smarty/Smarty.class.php';
$path=dirname(str_replace('\\','//',__FILE__));//模板配置
$smarty=new Smarty();
$smarty->template_dir=$path;//模板文件路径
$smarty->compile_dir=$path.'/Compile';//编译目录
$smarty->cache_dir=$path.'/Cache';//缓存
$smarty->left_delimiter='{';//模板标签左
$smarty->right_delimiter='}';//模板标签右
$smarty->caching=true;//缓存开启
$smarty->cache_lifetime=60;//缓存时间
 四、display和assign原理实现

创建index.html

$tpl=$path.'/index.html';
$smarty->assign('a',time());//赋值
$smarty->display($tpl);//显示对应模板
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
{$a}
</body>
</html>

http://www.lryc.cn/news/97242.html

相关文章:

  • 《TCP IP网络编程》第十一章
  • Folx Pro 5 最好用的Mac磁力链接BT种子下载工具
  • Redis 数据库的高可用
  • elementPlus dialog组件设置可拖动,当内容高度大于视口高度拖动显示异常的解决办法
  • 亲测解决Git inflate: data stream error (incorrect data check)
  • Ansible 自动化运维工具
  • node.js 爬虫图片下载
  • VAE-根据李宏毅视频总结的最通俗理解
  • 【LangChain】检索器之上下文压缩
  • uniapp 语音文本播报功能
  • 腾讯云高IO型云服务器CPU型号处理器主频性能
  • 【数据结构】实验八:树
  • kafka消费者api和分区分配和offset消费
  • 【驱动开发day4作业】
  • Ubuntu 20.04 Ubuntu18.04安装录屏软件Kazam
  • ADC 的初识
  • MMdetection框架速成系列 第07部分:数据增强的N种方法
  • 基于Kitti数据集的智能驾驶目标检测系统(PyTorch+Pyside6+YOLOv5模型)
  • 4.4. 深拷贝 vs 浅拷贝
  • 网络安全(黑客)自学建议笔记
  • Linux CentOS快速安装VNC并开启服务
  • redis到底几个线程?
  • mysql修改UUID
  • NoSQL之redis配置与优化
  • Python单例模式介绍、使用
  • 1334179-85-9,BTTAA,是各种化学生物学实验中生物偶联所需
  • Linux系统中的SQL语句
  • 力扣27 26 283 844 977 移除数组
  • 【沐风老师】3DMAX自动材质插件使用方法教程
  • 让你 React 组件水平暴增的 5 个技巧