美文网首页
Todolist--(8)Smarty模板引擎

Todolist--(8)Smarty模板引擎

作者: snoweek | 来源:发表于2015-05-22 21:17 被阅读178次

根据之前对todolist的了解,我们知道每一个页面都有以及链接中的其中几个
(1)登录
(2)注销
(3)注册
(4)更改密码
(5)返回首页
因此,决定对这几个链接写一个简单的模板。
1.在\Smarty\templates文件夹下建立一个index.html文件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>{$title}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
    <body>
        <h2 align="center">{$content}</h2>
        <a href="{$name1}.php" >{$content1}</a>
        <br />
        <a href="{$name2}.php" >{$content2}</a>
        <br />
        <a href="{$name3}.php" >{$content3}</a>
        <br />
        <a href="welcome.php">返回首页</a>
        <br />
    </body>
</html>

2.改写之前的Todolist程序
改写后

<?php
session_start();
include("../config.php");
$smarty->assign('title','欢迎页面');
$smarty->assign('content','Todolist,热烈欢迎你!');
if(isset($_SESSION['user_id'])){
    $smarty->assign('name1','logout');
    $smarty->assign('content1','注销');
    $smarty->assign('name2','changepassword');
    $smarty->assign('content2','更改密码');
    $smarty->assign('name3','list');
    $smarty->assign('content3','计划列表');

}else{
    
    $smarty->assign('name1','login');
    $smarty->assign('content1','登录');
    $smarty->assign('name2','register');
    $smarty->assign('content2','注册');
}
$smarty->display('todo.html');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="[http://www.w3.org/1999/xhtml]()" lang="[zh-CN]()">
<head><title>欢迎页面</title>
<meta http-equiv="[Content-Type]()" content="[text/html; charset=utf-8]()" />
</head>
 <body> <h2 align="[center]()">Todolist,热烈欢迎你!</h2> 
<a href="[login.php](view-source:http://127.0.0.1/sunyan2015/015/login.php)" >登录</a> <br /> 
<a href="[register.php](view-source:http://127.0.0.1/sunyan2015/015/register.php)" >注册</a> <br /> 
<a href="[.php](view-source:http://127.0.0.1/sunyan2015/015/.php)" ></a> <br /> 
<a href="[welcome.php](view-source:http://127.0.0.1/sunyan2015/015/welcome.php)">返回首页</a> <br /> 
</body>
</html>

改写前
index.php

<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>欢迎页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
    <body>
        <h1>欢迎访问todolist</h1>   
    </body>
</html>
<?php
if(isset($_SESSION['user_id'])){
    echo'<a href="logout.php">注销</a>';
    echo"<br />";
    echo'<a href="changepassword.php">更改密码</a>';
}else{
    echo'<a href="login.php">登录</a>';
    echo"<br />";
    echo'<a href="register.php">注册</a>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml]()" lang="[zh-CN]()">
<head>
<title>欢迎页面</title>
<meta http-equiv="[Content-Type]()" content="[text/html; charset=utf-8]()" />
</head>
 <body>
 <h1>欢迎访问todolist</h1>  
</body>
</html>
<a href="[login.php](view-source:http://127.0.0.1/sunyan2015/013/login.php)">登录</a><br />
<a href="[register.php](view-source:http://127.0.0.1/sunyan2015/013/register.php)">注册</a>

从改写前,改写后的代码,运行结果和页面源代码,我们看出Smarty模板引擎的运行机制与结果。

相关文章

  • Todolist--(8)Smarty模板引擎

    根据之前对todolist的了解,我们知道每一个页面都有以及链接中的其中几个(1)登录(2)注销(3)注册(4)更...

  • 2018-05-11Smarty模板引擎

    Smarty(模板引擎) 一、什么是模板引擎? Smarty是一个php模板引擎。更准确的说,它分开了逻辑程序和外...

  • Smarty模板

    PHP模板引擎 该文档使用的是Smarty 3.1.33 Released版本 什么是PHP模板引擎? php模板...

  • Smarty 模板函数

    最近工作中用到 Smarty 模板引擎,整理了一些用到的模板函数。 假设 smarty 的定界符为 {}。 模板中...

  • smarty模板引擎

    一、模板引擎的工作原理 1、实现HTML代码和PHP代码简单分离,完全去除视图文件中的PHP标记 2、常用PHP模...

  • Smarty模板引擎

    模板引擎的作用是什么 对PHP语言熟悉的程序员就会知道有个Smarty的名词,那么这个具体是什么呢?smarty是...

  • smarty模板引擎

    1)、模板引擎概念 ❖ 模板引擎的功能是实现逻辑与显示相分离,使程序设计者可以专注于程序功能的开发,使网页设计师专...

  • Smarty模板引擎

    Smarty

  • Smarty--(2)创建配置文件

    完成Smarty配置工作是应用Smarty模板引擎的关键。config.php 下面,我们来一一解读1.defin...

  • 微擎模板引擎

    $this->template('xxx')说明 类似smarty模板引擎 1、如果写在模块的前台方法functi...

网友评论

      本文标题:Todolist--(8)Smarty模板引擎

      本文链接:https://www.haomeiwen.com/subject/dwalqttx.html