• Smarty环境配置


    Smaty优点:1.代码分离 2.缓存技术

    使用步骤:

    1.下载Smaty模板

    2.将模板中那个lib文件夹复制到项目中(一般为根目录,并且重命名在此命名为Smarty)

    3.配置PHP

    1.新建一个Smarty_inc.php文件

    2.输入

    Include_once("Smarty/Smarty.class.php");//包含Smarty

    $smarty=new Smarty();//实例化Smarty对象

    //配置

    $smarty->config_dir="Smaryt/Config_File.class.php";

    配置文件目录路径,一般不更改

    $smarty->caching=false;

    是否开启缓存

    $smarty->template_dir="./templates";

    设置模板目录,手动创建,./代表当前目录必须设置

    $samrty->complie_dir="./templates_c";

    设置编译目录,手动创建,必须设置

    $smarty->cache_dir="./smarty_cache";

    设置缓存目录

    $smarty->left_delimiter="{";$smarty->right_delimiter="}";

    设置在HTML标志Smarty的开始和结束标签自定义也可以世{%%}

    Smarty使用变量

    定义变量

    $smarty->assign("模板变量","/数组");

    将改变量应用到特定的模板中

    $smarty->display("模板名");

    Eg:

    $smarty->assign("title","我的第一个smarty程序")

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

    index.html中使用

    <html>

    <head>

    <title>{$title}</title>

    </head>

    </html>

    上述一次只能访问一个变量那么怎样循环访问多个变量呢?

    要想访问多个变量必须用到数组

    定义

    $array={name->"jiangtong",name->"张三",name->"李四"}

    $smarty->assign($student,$name);

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

    index.html中使用

    <html>

    <head></head>

    <body>

    {section name="stuList"  loop="$student"}

    loop代表循环那个数组

    <p>{$student[stuList].name}</p>

    <sectionelse>

    //可以不写

     

    {/section}

     

    <body>

    </html>

     

    Smarty取出当前时间

    {$smarty.now}

  • 相关阅读:
    flutter 右滑返回上一页
    flutter 的Animation简单了解
    Flutter Offstage、Visibility隐藏/可见
    flutter手势
    Flutter生命周期
    flutter 路由动画
    flutter 保持页面状态
    flutter 不规则底部工具栏实现
    flutter 主页面底部导航栏实现以及主题风格设置
    flutter DropdownButton使用
  • 原文地址:https://www.cnblogs.com/aiqingqing/p/4493399.html
Copyright © 2020-2023  润新知