zoukankan      html  css  js  c++  java
  • PHP之Smarty学习

    参考网络上的资料,使用Smarty可以简单的测试:

    1.解压Smarty到网站目录下,比如起名libs.

    2.建立templates,templates_c,configs,cache目录

    3.建立测试页面:index.php

    <?php
    require "main.php";

    //$tpl在main.php中定义


    $tpl->assign("title", "测试用的网页标题");
    $tpl->assign("content", "测试用的网页内容");
    // 上面两行也可以用这行代替
    // $tpl->assign(array("title" => "测试用的网页标题", "content" => "测试用的网页内容"));
    $tpl->display('Index.htm');
    ?>

    4.在templates下建立模板文件index.htm

    <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      <title><{$title}></title>
      </head>
      <body>
      <{$content}>
      </body>
      </html>

    5.建立main.php

    <?php

    /*下面这加如果不加会报告错误:

    Notice: Undefined variable: _SESSION in E:\PHPnow-1.5.1\vhosts\xxh.com\libs\Smarty.class.php on line 585

    不知道为什么

    */
    session_start();//开启session
    include "libs/Smarty.class.php";
    define('__SITE_ROOT', 'E:/PHPnow-1.5.1/vhosts/xxh.com'); // 最后没有斜线
    $tpl = new Smarty();
    $tpl->template_dir = __SITE_ROOT . "/templates/";
    $tpl->compile_dir = __SITE_ROOT . "/templates_c/";
    $tpl->config_dir = __SITE_ROOT . "/configs/";
    $tpl->cache_dir = __SITE_ROOT . "/cache/";
    $tpl->left_delimiter = '<{';
    $tpl->right_delimiter = '}>';
    ?>

    6.打开index.php即可以测试Smarty了.

  • 相关阅读:
    ORA-01219:数据库未打开:仅允许在固定表/视图中查询
    RMAN-08137: WARNING: Archived Log Not Deleted, Needed For Standby Or Upstream Capture Proces
    SSDB 安装部署及注意事项总结
    Keepalived安装与配置
    MongoDB安装与配置
    mysql数据库优化建议
    mysql数据库主从复制搭建
    MySQL MHA安装与配置
    CDH版本的hadoop下载
    centos7下载
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/1467260.html
Copyright © 2011-2022 走看看