zoukankan      html  css  js  c++  java
  • smarty的应用

    smarty的应用,首先创建一个php文件
    <?php

    error_reporting(E_ALL & ~E_DEPRECATED);//避免过期出现的问题
    include_once('mypdo.php');//读取你自己封装的连接数据库的文件
    header('content-type:text/html;charset=utf-8');
    $mypdo = new MyPdo();
    $sql = "select * from book where id = ?";//SQL语句

    $booklist = $mypdo->pdoPrepare($sql,array($_GET['id']));


    $mypdo = null;//关闭数据库
    include_once("libs/Smarty.class.php"); //包含smarty类文件

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

    $smarty->caching=false; //是否使用缓存,项目在调试期间,不建议启用缓存

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

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

    //$smarty->cache_dir = "./smarty_cache"; //缓存文件夹

    //左右边界符,默认为{},但实际应用当中容易与JavaScript相冲突
    //因此建议替换为<{}>
    $smarty->left_delimiter = "<{";
    $smarty->right_delimiter = "}>";

    $smarty->assign("booklist",$booklist);//传递的变量名和值;


    $smarty->display('my.tpl')//需要显示的模板文件,后缀名可以随便写

  • 相关阅读:
    (转) IOS ASI http 框架详解
    不是技术牛人 如何拿到IT巨头的Offer 来自作者: lsldd 来源: CSDN
    数据类型Block 粗解
    GCD的基本思想
    自定义Cell的 两种方法!
    全世界最幸运的我
    实现鸢尾花数据的读入
    Tensorflow2的基本用法
    6.17
    6.16
  • 原文地址:https://www.cnblogs.com/223y/p/5636302.html
Copyright © 2011-2022 走看看