smarty实例

Posted F4ntasy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了smarty实例相关的知识,希望对你有一定的参考价值。

login.php代码

<?php
include("../init.inc.php");

$smarty->display("login.html");

login.html代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<h1>登陆页面</h1>
<form action="loginchuli.php" method="post">
<div>用户名:<input type="text" name="uid" /></div>
<div>密码:<input type="password" name="pwd" /></div>
<div ><input type="submit" value="登陆" /></div>
</form>
<body>
</body>
</html>

效果:

loginchuli.php 代码

<?php

include("../DBDA.class.php");
$db=new DBDA();
$uid=$_POST["uid"];
$pwd=$_POST["pwd"];
$sql="select pwd from user where uid=\'{$uid}\'";
$mm=$db->StrQuery($sql);
if($pwd=$mm && !empty($pwd))
{
header("location:main.php");
}

main.php 代码

<?php
include("../init.inc.php");
include("../DBDA.class.php");
$db=new DBDA();
$tj=" 1=1 ";
if(!empty($_GET["name"]))
{ $n=$_GET["name"];
$tj="name like\'%{$n}%\'";
}
$ztj=" where {$tj} ";
$sall=" select count(*) from course ".$ztj;
$zts=$db->StrQuery($sall);
include("../page.class.php");
$page=new Page($zts,5);

$sql=" select * from course ".$ztj.$page->limit;
$arr=$db->Query($sql);
$smarty->assign("fenye",$page->fpage());
$smarty->assign("shuzu",$arr);
$smarty->display("main.html");

main.html代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>显示页面</h1>
<form action="main.php" method="get">
<div><input type="text" name="name" />
<input type="submit" value="查找" />
</div>
</form>
<table width="100%" cellpadding="0px" cellspacing="0px" border="1px">
<tr>
<td>代号</td>
<td>课程</td>
<td>类型</td>
<td>操作</td>


</tr>
<{foreach $shuzu as $v}>

<tr>
<td><{$v[0]}></td>
<td><{$v[1]}></td>
<td><{$v[2]}></td>
<td><a href="xiugai.php?code=<{$v[0]}>">修改</a></td>


</tr>
<{/foreach}>
</table>
<div><{$fenye}></div>

</body>
</html>

 

 

效果:

xiugai.php

<?php
include("../init.inc.php");
include("../DBDA.class.php");
$db=new DBDA();
$code=$_GET["code"];
$sql="select * from course where code=\'{$code}\'";
$arr=$db->Query($sql);
$smarty->assign("course",$arr[0]);
$smarty->display("xiugai.html");

 

xiugai.html代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>修改页面</h1>
<form action="update.php" method="post">
<div>代号:<input type="text" name="code" value="<{$course[0]}>" /></div>
<div>课程:<input type="text" name="course" value="<{$course[1]}>" /></div>
<div>类型:<input type="text" name="type" value="<{$course[2]}>"/></div>
<input type="submit" value="修改" />
</form>
</body>
</html>

效果

 

以上是关于smarty实例的主要内容,如果未能解决你的问题,请参考以下文章

php封装的smarty类实例是怎样

PHP 模板smarty练习

smarty模板引擎

Smarty常用函数

php常见面试(Smarty及相关知识)

smarty 快速入门