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. Akka系列(六):Actor解决了什么问题?

    前言..... 文档来源于  : What problems does the actor model solve? Actor解决了什么问题? Akka使用Actor模型来克服传统面向对象编程模型的 ...

  2. RPCVersionCapError: Requested message version, 4.17 is incompatible. It needs to be equal in major version and less than or equal in minor version as the specified version cap 4.11.

    [问题描述] RPCVersionCapError: Requested message version, 4.17 is incompatible. It needs to be equal in ...

  3. tez

    参考: 原理: https://www.cnblogs.com/rongfengliang/p/6991020.html https://www.cnblogs.com/hankedang/p/421 ...

  4. Objective-C中的自动释放池

    自动释放池块@autoreleasepool 自动释放池块在MRC和ARC下都可以使用.在MARC下,为了将自动释放池块内部的变量放入自动释放池,需要手动调用autorelease方法:在ARC下,只 ...

  5. 存储过程实例基于postgersql

    数据库用的是postgersql 数据库管理工具是DBeaver  mybatis操作数据库基于jdbcTemplate 1.写的存储方法放在数据库下面的Procedures目录下 function ...

  6. 设计模式之单例模式(Singleton Pattern)

    单例模式是最简单的设计模式之一.属于创建型模式,它提供了一种创建对象的最佳方式.使应用中只存在一个对象的实例,并且使这个单实例负责所有对该对象的调用.这种模式涉及到一个单一的类,该类负责创建自己的对象 ...

  7. Mac 基于Anaconda的TensorFlow安装笔记

    最近在中国大学MOOC平台学习北大的曹健老师上的“人工智能实践——Tensorflow”课程,开始我的人工智能之旅.第一天,讲解如何搭建实验室环境,我是mac系统,所以只写mac系统上的实验室环境安装 ...

  8. poj2186--tarjan+缩点(有向图的强连通分量中点的个数)

    题目大意:       每一头牛的愿望就是变成一头最受欢迎的牛.现在有N头牛,给你M对整数(A,B),表示牛A认为牛B受欢迎. 这 种关系是具有传递性的,如果A认为B受欢迎,B认为C受欢迎,那么牛A也 ...

  9. win10 powershell禁止运行脚本解决

    win10 现在默认策略为 Restricted 该策略情况下是禁止在终端下运行脚本文件的,所以我们想要通过powershell 来运行我们的脚本文件的话就需要我们更改其策略才行,如下命令可以帮助你 ...

  10. cmd内部命令和外部命令的区别

    内部命令 我们可以直接在CMD下就可以执行的命令,例如:telnet.ftp.dir.cd.等等,你可以在CMD下输入help进行查看 外部命令 就是cmd下不能直接运行的命令,(例如大家常用的nc) ...