• 如何配置Smarty模板


    <?php

    //首先包含Smarty类文件

    include_once('Smarty/Smarty.class.php');

    //实例化Smarty类文件

    $smarty=new Smarty();

    //设置配置目录,可以不设置

    //注意一下文件夹需要自己创建,并且可以改名

    //$smarty->config_dir=

    //$smarty->cache_dir="./caches";//设置缓存目录

    //$smarty->caching=true;//关闭缓存,调试中建议关闭默认为关闭即设置成false

    $smarty->cache_lifetime=60;//单位为秒     设置缓存时间

    $smarty->template_dir="./templates";//设置模版目录

    $smarty->compile_dir="./templates_c";//设置编译目录必选

    $smarty->cache_dir="./smarty_cache";//缓存文件夹可选为减轻压力

    //设置开始结束边界默认为{} 但容易与javascript冲突

    $smarty->left_delimiter="{";

    $smarty->right_delimiter="}";

    ?>

    4.演示一下Smarty模板的使用  

    新建一个php文件 文件名为helloworld.php  代码如下

    <?php

    //包含smarty配置文件

    include 'smarty.inc.php';

    //将变量name赋值为helloworld

    $smarty->assign('name','Hello world!');

    //在模板下的helloworld.html文件显示注意这里必须对应的是模板目录下的helloworld.html换成别的文件名不行,必须和php的文件对应

    $smarty->display('helloworld.html');

    ?>

    设置helloworld.html文件

    <html>

    {$name}<!--输出到浏览器页面-->

    </html>

    注意:两个文件名必须相同除扩展名!还要将smarty.inc.php 和helloworld.php放于同一目录下

    5.下来就可以参考Smarty手册和demo尝试了,一起加油phper!

  • 相关阅读:
    Android购物商城
    Android简易计算器
    安卓第四周作业
    第一次安卓作业
    十五周课后习题
    第十三周作业
    十三周上机练习
    第十二周作业
    第十二周练习
    11周上机作业(5.14)
  • 原文地址:https://www.cnblogs.com/achengmu/p/3866291.html
Copyright © 2020-2023  润新知