smarty 笔记
display():
把html包含进来
然后用正则匹配php变量
把匹配好的页面重新保存
inclue载入刚才的保存的页面

1.smarty原理
2.smarty安装
3.smarty模板设计
4.smarty程序设计

四个默认文件夹//可在 smarty().__construct改
cache
configs
templates
templates_c

style 和 script的 {} 要注意替换 用left_delimiter("<{")
$s->right_delimiter("}>")
使用模板的时候 smarty就用<{ 代替{
$s->caching = true;//开启缓存

包含图片,css,js要相对于index.php的路径,因为index.php包含执行

./当前目录
../上级目录

基本语法:
注释 {* xxxxx *}

模板中的类对象
$s->assign("obj",new Person());

{config_load "index.conf"} // bgcolor="#ccc";
<body bgcolor="{#bgcolor#}">

操纵php超全局数组
$smarty.get.id <===> $_GET['id'];

//pdo
$pdo = new pdo("mysql:host=localhost;dbname=test","root","root");
$pdo -> setAttribute (PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
$pdo -> setAttribute (PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$pdo ->exec("set names utf8");

//分页
<?php
include ("smarty.inc.php");
include ("pdo.inc.php");

$page = $_GET['page']?$_GET['page']:1;
echo $s->isCached($smarty_dir."/templates/index.html",$page);
if(!$s->isCached($smarty_dir."/templates/index.html",$page))
{
$totsql = "select count(*) from user";
$sth = $pdo -> prepare($totsql);
$sth ->execute();
$tots = $sth -> fetchColumn();

$length = 3;
$offset = ($page - 1) * $length;

$prepage = $page - 1;
$nextpage = $page;
if($nextpage < ceil($tots/$length))
{

$nextpage = $page + 1;
}
else{
$nextpage = $page;
}
$sql = "select * from user order by id limit $offset,$length";
$sth = $pdo->prepare($sql);
$sth -> execute();
$rows = $sth -> fetchALL();
$s -> assign("rows",$rows);
$s -> assign("prepage",$prepage);
$s -> assign("nextpage",$nextpage);
}

$s -> display($smarty_dir."/templates/index.html",$page);
?>

index.html
<body>
<table width="500px" border="3px solid #ccc">
<{foreach $rows as $val}>
<tr>
<td><{$val.id}></td>
<td><{$val.username}></td>
</tr>
<{/foreach}>
</table>
<a href="../index.php?page=<{$prepage}>" title="">上一页</a>|
<a href="../index.php?page=<{$nextpage}>" title="">下一页</a>
</body>

smarty笔记的更多相关文章

  1. Smarty笔记 和20个常用的变量操作符

    什么是Smarty变量操作符php模板引擎smarty内置的一些操作函数,我们称之为变量操作符,变量操作符可用于操作变量,自定义函数和字符.(跟我PHP中常用的PHP内部函数类似)他可以帮助我们完成很 ...

  2. 160726 smarty 笔记(1)

    模板里面显示变量:1.变量要写在Smarty标记之间,变量名以$开头<{$test}>2.支持所有类的数据,包括数组(关联数组),对象关联数组在模板显示的时候,除了可以使用php语法之外, ...

  3. 160726 smarty 笔记(2)

    <?php //取当前页 $p=1; if(!empty($_GET["page"])) { $p=$_GET["page"]; } //定义页面缓存文件 ...

  4. smarty之缓存笔记

    smarty缓存技术 在smarty中,缓存分为:普通缓存,单模版都缓存,局部缓存. 缓存:1:首选打开缓存配置项:$smarty->caching=true; 2:缓存生命周期的配置选项:$s ...

  5. Smarty学习笔记(二)

    1.引用 {include file="xxx.xxx" sitename="xxx"} 向引入的文件传入变量: {include file="xxx ...

  6. Smarty学习笔记(一)

    1.Smarty的配置: 将lib的内容复制到自己的工程,然后引入 实例化和配置Smarty基本属性: $smarty = new Smarty(); $smarty->left_delimit ...

  7. PHP-MVC和Smarty初探笔记

    在慕课网上学习了PHP的MVC的基础知识,记录一下笔记: 等待更新~

  8. smarty详细使用教程(韩顺平smarty模板技术笔记)

    MVC是一种开发模式,强调数据的输入.处理.显示是强制分离的 Smarty使用教程1.如何配置我们的smarty解压后把libs文件夹放在网站第一级目录下,然后创建两个文件夹templates 存放模 ...

  9. Yaf + Smarty 整合笔记

    Yaf真的是太简单了,简单到使用mvc的时候在view里面需要手写php脚本.因此考虑整合一下smarty模板引擎.随心所欲也正是yaf的魅力 Yaf 安装 这里简单说一下yaf的安装,已经是非常无脑 ...

随机推荐

  1. 第五周课程总结&实验报告(三)

    实验三 String类的应用 实验目的: (1)掌握类String类的使用: (2)学会使用JDK帮助文档: 实验内容: 1.已知字符串:"this is a test of java&qu ...

  2. spring boot-8.静态资源映射

    1.webjars WebJars是将客户端(浏览器)资源(javascript,Css等)打成jar包文件,以对资源进行统一依赖管理.WebJars的jar包部署在Maven中央仓库上.官网地址:h ...

  3. MySQL5.6解压版服务无法启动—系统错误1067

    记录一下今天被坑了一下午的BUG 就从半个月前说起吧 当时....................................................................... ...

  4. 项目中使用vue的API。 和项目的结构

    <template> <!--组件的 结构--> <div id="app"> <h3>{{ msg }}</h3> & ...

  5. python 类(2)

    """ """class BaseCat(object): """ 猫科基础类""&quo ...

  6. 异常:Caused by: java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext

    说明项目没有加载jar包 异常:Caused by: java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplic ...

  7. Core Graphics Paths

    Paths中的几个重要元素 Points void CGContextMoveToPoint (    CGContextRef c,    CGFloat x,    CGFloat y ); 指定 ...

  8. Python杂章

    IDLE常用的快捷键: Ctrl+]:缩进代码 Ctrl+[:取消缩进 Alt+3:注释代码 Alt+4:去掉注释 F5:运行代码 Ctrl+Z:撤销一步 print('你好,Python!')

  9. inux下:热插拔和模块是什么

    一.何为模块? 文件系统.设备驱动程序.网络协议都可以理解为模块.模块本质也是普通的软件系统. 二.热插拔 硬件层面:只在不断电.不关闭系统的情况下增加或者删除对应部件,比如电源.硬盘.一些高端设备硬 ...

  10. PAT Basic 1086 就不告诉你 (15 分)

    做作业的时候,邻座的小盆友问你:“五乘以七等于多少?”你应该不失礼貌地围笑着告诉他:“五十三.”本题就要求你,对任何一对给定的正整数,倒着输出它们的乘积. 输入格式: 输入在第一行给出两个不超过 10 ...