一,Smarty模板技术/引擎——简介
2024-10-21 12:37:19
Smarty是一个使用PHP写出来的模板PHP模板引擎,它提供了逻辑与外在内容的分离,简单的讲,目的就是要使PHP程序员与美工分离,使用的程序员改变程序的逻辑内容不会影响到美工的页面设计,美工重新修改页面不会影响到程序的程序逻辑,这在多人合作的项目中尤为重要。场景一就是登陆之后,跳转到列表页时候,列表页再获取列表数据,如图1。使用smarty后,登陆成功之后,获取列表数据,通过smarty将列表数据发送到列表页,如图2。
图1 图2
在项目中使用smarty,需要引入smarty包,下载smarty,解压缩后,将libs文件夹复制到项目中即可。项目中新建templates和templates_c文件夹,前一个存放模板,后一个存放templates模板对应的编译文件,两个都必不可少。templates里面文件后缀名随意,习惯用tpl和php。项目目录如下图所示,listProcess.class.php代码页此处没有详解。
代码页如下:
login.php
<form action="LoginProcess.php" method="post">
<h1>登陆页面</h1>
用户名:<input type="text" name="username"><br/>
密 码:<input type="password" name="password"><br/>
<input type="submit" value="登陆"><input type="reset" value="重新填写">
</form>
loginProcess.php
<?php
$username = $_POST['username'];
$password = $_POST['password']; if($username == 'aaa' && $password =='aaa'){
require_once "listProcess.class.php";
require_once "./libs/Smarty.class.php";
$listProcess = new listProcess();
$res = $listProcess->showEmpList(); $smarty = new Smarty();
$smarty->assign("res",$res);
$smarty->display("empList.php");
// header("Location:EmpList.php");
}else{
header("Location:login.php");
}
templates/empList.php
<html>
<h1>显示记录</h1>
<body>
<table>
<tr><td>id</td><td>name</td><td>password</td></tr>
{foreach from=$res item=res}
<tr><td>{$res.empid}</td><td>{$res.name}</td><td>{$res.password}</td></tr>
{/foreach}
</table>
</body>
</html>
最新文章
- OC中用NSSortDescriptor对象进行数组排序
- WinForm控件TreeView 只部分节点显示 CheckBox
- 【BZOJ-1026】windy数 数位DP
- 【POJ3461】Olipo
- servlet servlet请求与响应
- Crystal Reports ";Access to report file denied. Another program may be using it.";
- 使用SignalR+Asp.net创建实时聊天应用程序
- IOS内存管理「1」- 引用计数
- 宏FSP_SEG_INODES_PER_PAGE
- object-c 内存管理机制的学习
- 程序员之---C语言细节22(函数返回指针注意事项&;lt;悬空指针&;gt;、查看进程能够分配的内存大小)
- 【百度地图API】——如何让标注自动呈现在最佳视野内
- 从零开始学C#——基本语法(二)
- Nginx平台构架
- python标准日志模块logging及日志系统设计
- PHP学习笔记2
- 蓝牙进阶之路 (003) - AT指令(转)
- Redis 操作列表数据
- django 加载静态文件(图片,js,css)
- Cocos2d-JS实现的2048
热门文章
- const&;static&;extern
- zabbix主机自动注册
- PythonScripter2.7报错ascii codec can&#39;t encode characters in position 0-1:ordinal not in range(128)
- Windows下redis的安装与使用
- ECS 游戏架构 理解
- Python爬虫实战一之爬取糗事百科段子
- vnpy自动化交易
- Oracle 11g 重建EM需要删除的对象
- Smarty的基本语法------变量调节器
- [GO]结构体指针类型匿名字段