zoukankan      html  css  js  c++  java
  • PHP Smarty模板的安装

    最近开发中用到了PHP中smarty模板。。作为一个长久以来的前端,开始学习PHP模板。。下面将安装教程分享给大家。。

    1. 下载Smarty最新版: http://www.smarty.NET/download

    2. libs目录下的文件都是Smarty需要的库文件,只要将该文件夹拷贝到要使用Smarty技术的网站根目录就能够使用Smarty了。为了不和已有的文件夹重名,可以修改文件夹的名字为Smarty。

    3.在网站根目录下建立如下的目录结构 来测试Smarty的使用。

    ----Smarty-learn

    --------------------smarty(smarty的库文件)

    --------------------templates---cache

    ------------------------------------config

    ------------------------------------templates--------index.html(模版文件)

    ------------------------------------templates_c

    --------------------index.PHP

    index.html 的内容:

    <html>
    <title><head>test smarty</head></title>
    <body>
    {$color}
    </body>
    </html>

    index.php的内容:

    <?PHP
    //引用类文件?
    require 'smarty/Smarty.class.php';
    $smarty = new Smarty;
    //设置各个目录的路径,这里是安装的重点
    $smarty->template_dir="templates/templates";
    $smarty->compile_dir="templates/templates_c";
    $smarty->config_dir="templates/config";
    $smarty->cache_dir="templates/cache";
    //smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决
    $smarty->caching=false;
    $hello = "hello smarty!";
    $smarty->assign('hello',$hello);
    $bgcolor = "green";
    $smarty->assign('color',$bgcolor);
    $smarty->display('index.html');
    ?>

    在浏览器输入http://localhost/Smarty-learn/,如果出现green,说明测试成功,Smarty没有任何问题,已经可以使用了。

    这样的目录结构并不是必须的,只要在使用Smarty的时候配置好这几个目录的路径,任何目录结构都是可以的。但是建议这样使用,层次清楚,不影响网站其他部分。

  • 相关阅读:
    结构型设计模式——享元
    结构型设计模式——装饰模式
    结构型设计模式——外观
    结构型设计模式——桥接模式
    结构型设计模式——适配器模式(Go)
    创建型设计模式——工厂模式
    创建型设计模式——单例模式
    Linux03
    阅读《构建之法》八九十章
    作业五 5.2 5.3
  • 原文地址:https://www.cnblogs.com/HanJie0824/p/6433811.html
Copyright © 2011-2022 走看看