Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2779449
  • 博文数量: 77
  • 博客积分: 10204
  • 博客等级: 上将
  • 技术积分: 5035
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-05 22:13
文章分类
文章存档

2013年(1)

2010年(1)

2009年(17)

2008年(58)

我的朋友

分类:

2009-12-04 13:12:31

 

Smarty类扩展:

<?php
    /*
     *
     * This class extends Smarty, it used to initializing smarty.
     *
     */

    /* Load smarty library */
    require('Smarty/Smarty.class.php');
    
    /*
     * Initializing Smarty class
     */

    class Template extends Smarty
    {
        const debuging = true;
        const left_delimiter = '';
        const caching = 0;
        const cache_lifetime = '1800';
       /*
        * Construct
        *
        * @access public
        * @param $cacheing default 1(using caching level 1)
        * @return None
        */

        public function __construct()
        {
            $this->Smarty();
            $this->template_dir = SITE_ROOT . 'themes/default/';
            $this->compile_dir = SITE_ROOT . 'tmp/templates_c/';
            $this->config_dir = SITE_ROOT . 'includes/Smarty/configs/';
            $this->cache_dir = SITE_ROOT . 'tmp/smarty_cache/';
            
            /* Enable debugging*/
            $this->debugging = self::debuging;
            /*
             * Enable caching
             *
             * By default this is set to 0
             *
             * A value of 1 or 2 enables caching.
             *
             * 1 use the current $cache_lifetime variable to determine if the cache has expired.
             * 2 lifetime is per cache
             */

            $this->caching = self::caching;
            
            if(1 == $this->caching)
            {
                $this->cache_lifetime = self::cache_lifetime; // 30 minutes

            }
            
            /* Friendly to designer */
            $this->left_delimiter = self::left_delimiter;
            $this->right_delimiter = self::right_delimiter;
        }
        
       /*
        * Set template dir
        *
        * @access public
        * @param string $dir
        * @return None
        */

       public function setTemplateDir($dir)
       {
           $this->template_dir = $dir;
           $this->config_dir = dirname($dir) . '/configs';
           $this->compile_id = md5($dir);
       }
    }
?>


 

主题切换:

/*
  * Set smarty library and muti themes / styles
  */
    $theme = isset($_GET['theme']) ? $_GET['theme'] : 'default';
    $tpl = new Template();
    $tpl->setTemplateDir(SITE_ROOT . 'themes/' . $theme . '/templates');


 

目录结构:

themes |-default|-configs
           | |-js
           | |-css
           | |-templates
           |
           |
           |-other


阅读(1602) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

zlt8201072009-12-07 20:39:13

不错