zoukankan      html  css  js  c++  java
  • 扩展设置

    扩展设置

    这是基本安装的继续,请先阅读那个文件!

    一个更灵活一点的配置Smarty的方法是扩展类,和初始化你的smarty环境。
    为了避免重复地配置路径,我们可以在一个文件里配置这些变量。
    我们创建一个目录 "/php/includes/guestbook/" 建立一个文件"setup.php"
    同样先设置好smarty路径。

    例2-10.编辑 /php/includes/guestbook/setup.php

     
    // load Smarty library
    require('Smarty.class.php');
    
    // The setup.php file is a good place to load
    // required application library files, and you
    // can do that right here. An example:
    // require('guestbook/guestbook.lib.php');是一个很好的加载应用程序的类库文件(就是扩展类)
    //例如你可以在index文件里包含它
    
    class Smarty_GuestBook extends Smarty {
    
     function Smarty_GuestBook() {
     
     		// Class Constructor. These automatically get set with each new instance.
     //类构造函数.创建实例的时候自动配置
    
    		$this->Smarty();
    
    		$this->template_dir = '/web/www.mydomain.com/smarty/guestbook/templates/';
    		$this->compile_dir = '/web/www.mydomain.com/smarty/guestbook/templates_c/';
    		$this->config_dir = '/web/www.mydomain.com/smarty/guestbook/configs/';
    		$this->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/'; 
    		
    		$this->caching = true;
    		$this->assign('app_name','Guest Book');
     }
    
    }


    现在我们针对setup文件更改一下index文件

    Smarty手册范例 2-11.编辑/web/www.mydomain.com/docs/guestbook/index.php

    require('guestbook/setup.php');
    
    $smarty = new Smarty_GuestBook;
    
    $smarty->assign('name','Ned');
    
    $smarty->display('index.tpl');

    现在你看到创建一个使用smarty的实例有多么的简单.从Smarty_GuestBook开始,重新构建我们的应用程序吧^_^

  • 相关阅读:
    分布式id生成
    DB主从一致性架构优化4种方法
    Mysql在大型网站的应用架构演变
    win10下iis绑定局域网ip无效的解决方案
    css随笔
    html标签说明
    C# JSON序列化日期格式问题
    使用事件机制相比直接调用函数的优势
    C#绑定事件时使用匿名函数
    C# t4模版引擎笔记 引入外部dll
  • 原文地址:https://www.cnblogs.com/danmao/p/4297488.html
Copyright © 2011-2022 走看看