zhphpframework (十三) smarty模板配置层

<?php
/**
 * Created by JetBrains PhpStorm.
 * User: 张华
 * Date: 14-3-8
 * Time: 下午12:21
 * QQ: 746502560@qq.com
 * To change this template use File | Settings | File Templates.
 */
defined('IN_ZHPHP')?NULL:die('attempts to hack the system');
final class template{
    private static $loadSmartyArr=array();
    #防止被实例化
    public   function __construct() { return; }

    /**
     * @return mixed|Smarty
     */
    private static function loadSmarty(){
         if(isset(self::$loadSmartyArr['Smarty'])){
               return unserialize(self::$loadSmartyArr['Smarty']);
          }else{
                 engine::loadExtends('vendors.Tpl.Smarty.Smarty','class');
                 $smarty=new Smarty();
                self::$loadSmartyArr['Smarty']=  serialize($smarty);
                return $smarty;
          }
      }
      /**
       * 设置模版变量
       * @param type $template_dir
       * @return type
       */
    public static function setTpl(){
		if(isset(self::$loadSmartyArr['tplObject'])){
				return self::$loadSmartyArr['tplObject'];
			}else{
		   $smarty=self::loadSmarty();
           $router=engine::getObject('router');
           $smartyConf=config::readConfig('tpl');
           $module=$router->getModule();#获取模块
           $module=empty($module)?null:$module.'/';
         if(empty($smartyConf['template_dir'])){
            $template_dir=empty($module)?APP_PATH.'views/':APP_PATH.'modules/'.$module.'views/';#得到模版目录地址
         }else{
            $template_dir=empty($module)?APP_PATH.$smartyConf['template_dir'].'/':APP_PATH.'modules/'.$module.$smartyConf['template_dir'].'/';#得到模版目录地址
          }
         $cache_dir= empty($smartyConf['cache_dir'])?APP_PATH.'caches/':APP_PATH.$smartyConf['cache_dir'].'/';
         $compile_dir= empty($smartyConf['compile_dir'])?APP_PATH.'runtime/':APP_PATH.$smartyConf['compile_dir'].'/';
        
         #配置smarty 参数
           $smarty->setTemplateDir($template_dir); #配置模板目录
           $smarty->compile_check=$smartyConf['compile_check'];#配置是否每次编译之前都检查是否有更新
           $smarty->setCompileDir($compile_dir);#smarty模板编译目录
          if($smartyConf['caching']){
             $smarty->caching=$smartyConf['caching'];#是否缓存
             $smarty->cache_lifetime=$smartyConf['cache_lifetime'];#缓存过期时间
             $smarty->setCacheDir($cache_dir);#缓存目录
           }
           $smarty->left_delimiter=$smartyConf['left_delimiter'];#左边界符号
           $smarty->right_delimiter=$smartyConf['right_delimiter'];#右边界符号
           $smarty->allow_php_templates=true;
           #$Smarty->allow_php_tag=true;#
           self::$loadSmartyArr['tplObject']=serialize($smarty);
           unset($smartyConf,$template_dir,$router,$module,$cache_dir,$compile_dir,$smarty);
           return self::$loadSmartyArr['tplObject'];
		}
   }       
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值