当前位置: 首页>>代码示例>>PHP>>正文


PHP Smarty::setCacheLifetime方法代码示例

本文整理汇总了PHP中Smarty::setCacheLifetime方法的典型用法代码示例。如果您正苦于以下问题:PHP Smarty::setCacheLifetime方法的具体用法?PHP Smarty::setCacheLifetime怎么用?PHP Smarty::setCacheLifetime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Smarty的用法示例。


在下文中一共展示了Smarty::setCacheLifetime方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * Create a new template object
  * @return object
  */
 public static function create()
 {
     // Try/catch statement
     try {
         // Required Smarty libraries
         require_once dirname(__DIR__) . '/smarty/libs/Smarty.class.php';
         // Optional - load custom security features
         //require_once(__DIR__.'/smartysecuritycustom.inc.php');
         // Smarty v3.1 or newer
         $smarty = new Smarty();
         $smarty->setTemplateDir(Config::read('smarty|templateDirectory'));
         $smarty->setCompileDir(Config::read('smarty|compileDirectory'));
         $smarty->setCacheDir(Config::read('smarty|cacheDirectory'));
         // Optional - override configs
         //$smarty->setConfigDir(Config::read('smarty|configDirectory'));
         // Optional - override plugins
         //$smarty->setPluginsDir(Config::read('smarty|pluginsDirectory'));
         $smarty->setCacheLifetime(Config::read('smarty|cacheLifetime'));
         // Disable caching
         $smarty->force_compile = true;
         $smarty->compile_check = true;
         $smarty->setCaching(Smarty::CACHING_OFF);
         // Optional - enable security restrictions
         //$smarty->enableSecurity('SmartySecurityCustom');
         // Return Smarty object
         return $smarty;
     } catch (Exception $e) {
         Log::error("Error while loading template engine");
         // Exception error
         return false;
     }
 }
开发者ID:noumenia,项目名称:aetolos,代码行数:36,代码来源:templatefactory.inc.php

示例2: smarty_helper_security_output_filter

require_once PROTECTED_PATH . '/Framework/Smarty/Smarty.class.php';
$smarty = new Smarty();
//修改 smarty 缺省的 {},太容易导致错误了
$smarty->left_delimiter = '{{';
$smarty->right_delimiter = '}}';
// smarty 缺省对所有的输出都要做 html_specialchars 防止出错
$smarty->escape_html = true;
// Smarty 严重安全漏洞,由于 smarty 不会过滤 <script language="php">phpinfo();</php> 这样的代码,我们只能自己过滤
function smarty_helper_security_output_filter($source, Smarty_Internal_Template $smartyTemplate)
{
    return preg_replace('/<script[^>]*language[^>]*>(.*?)<\\/script>/is', "", $source);
}
$smarty->registerFilter('output', 'smarty_helper_security_output_filter');
//缺省不缓存,防止出错,后面不同页面根据实际需要再自己定义缓存
$smarty->setCaching(Smarty::CACHING_OFF);
$smarty->setCacheLifetime(0);
/**
 * 定义全局的 smarty 缓存开关
 *
 * @param $enable boolean 开/关
 * @param $ttl    integer 缓存时间
 * @param $policy smarty 缓存时间的策略,比如 \Smarty::CACHING_LIFETIME_SAVED
 * */
function enableSmartyCache($enable, $ttl = 0, $policy = \Smarty::CACHING_LIFETIME_SAVED)
{
    global $f3;
    global $smarty;
    if ($enable && $f3->get('sysConfig[smarty_caching]')) {
        $smarty->setCaching($policy);
        $smarty->setCacheLifetime($ttl);
        return;
开发者ID:jackycgq,项目名称:bzfshop,代码行数:31,代码来源:bootstrap.php

示例3: getcwd

 * User: Erdal Gunyar
 * Date: 28/01/2016
 * Time: 11:48
 */
/* Path settings */
define('ROOT_DIR', getcwd() . '/');
/* Composer autoload */
require ROOT_DIR . 'app/vendor/autoload.php';
/* DB */
Propel::init(ROOT_DIR . 'db/build/conf/orm-conf.php');
/* Global variables */
global $_DATA, $_SMARTY;
$_DATA = [];
/* Smarty settings */
$_SMARTY = new Smarty();
$_SMARTY->setTemplateDir(ROOT_DIR . 'tpl');
$_SMARTY->setCompileDir(ROOT_DIR . 'app/cache/templates');
$_SMARTY->setCacheDir(ROOT_DIR . 'app/cache/full-page');
$_SMARTY->setConfigDir(ROOT_DIR . 'config/');
$caching = CACHING_ENABLED ? Smarty::CACHING_LIFETIME_CURRENT : Smarty::CACHING_OFF;
$_SMARTY->setCaching($caching);
$_SMARTY->setCacheLifetime(-1);
// Never expires
$_SMARTY->setCompileCheck(ENVIRONMENT == 'dev');
/* Session */
session_start();
if ($_SESSION['error']) {
    $_DATA['error'] = $_SESSION['error'];
    $_SESSION['error'] = false;
    unset($_SESSION['error']);
}
开发者ID:Erdou,项目名称:Rikiki-MVC,代码行数:31,代码来源:init.php

示例4: date

$log_file = date('Ymd') . '.log';
$log = new Logs($debug_mode, $log_file);
//读取网站设置
$get_sysconf = 'select `key`,`value` from ' . $db->table('sysconf');
global $config;
$config_tmp = $db->fetchAll($get_sysconf);
foreach ($config_tmp as $tmp) {
    $config[$tmp['key']] = $tmp['value'];
}
//初始化smarty对象
global $smarty;
$smarty = new Smarty();
$smarty->setCompileDir(ROOT_PATH . 'control/data/compiles');
$smarty->setTemplateDir(ROOT_PATH . 'control/themes/');
$smarty->setCacheDir(ROOT_PATH . 'control/data/caches');
$smarty->setCacheLifetime(1800);
//设置缓存文件超时时间为1800秒
//Debug模式下每次都强制编译输出
if ($debug_mode) {
    //$smarty->clearAllCache();
    //$smarty->clearCompiledTemplate();
    $smarty->force_compile = true;
}
//设置系统设置
assign('config', $config);
//设置语言包
assign('lang', $lang);
//设置网站参数
assign('config', $config);
//设置模板路径
assign('template_dir', 'themes/' . $config['themes'] . '/');
开发者ID:Winsen1990,项目名称:direct-sale,代码行数:31,代码来源:init.inc.php

示例5: project_history

 /**
  *
  */
 public static function project_history()
 {
     SystemEvent::raise(SystemEvent::DEBUG, "Called.", __METHOD__);
     if (empty($GLOBALS['project']) || !$GLOBALS['project'] instanceof Project || empty($_GET['bid'])) {
         $msg = 'Invalid request';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo json_encode(array('success' => false, 'error' => $msg));
         exit;
     }
     //
     // Viewing project build details
     //
     $build = null;
     // It's possible that no build was triggered yet.
     if (isset($_GET['bid']) && !empty($_GET['bid'])) {
         $build = Project_Build::getById($_GET['bid'], $GLOBALS['project'], $GLOBALS['user']);
     }
     if (!$build instanceof Project_Build) {
         $msg = 'Invalid request';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         echo json_encode(array('success' => false, 'error' => $msg));
         exit;
     }
     //
     // We need to process a Smarty file...
     // TODO: Centralize this
     //
     require_once CINTIENT_SMARTY_INCLUDE;
     $smarty = new Smarty();
     $smarty->setAllowPhpTag(true);
     $smarty->setCacheLifetime(0);
     $smarty->setDebugging(SMARTY_DEBUG);
     $smarty->setForceCompile(SMARTY_FORCE_COMPILE);
     $smarty->setCompileCheck(SMARTY_COMPILE_CHECK);
     $smarty->setTemplateDir(SMARTY_TEMPLATE_DIR);
     $smarty->setCompileDir(SMARTY_COMPILE_DIR);
     $smarty->error_reporting = error_reporting();
     Framework_SmartyPlugin::init($smarty);
     //
     // Special tasks. This is post build, so we're fetching an existing special task (never creating it)
     //
     $specialTasks = $build->getSpecialTasks();
     $smarty->assign('project_specialTasks', $specialTasks);
     if (!empty($specialTasks)) {
         foreach ($specialTasks as $task) {
             if (!class_exists($task)) {
                 SystemEvent::raise(SystemEvent::ERROR, "Unexisting special task. [PID={$GLOBALS['project']->getId()}] [BUILD={$build->getId()}] [TASK={$task}]", __METHOD__);
                 continue;
             }
             $o = $task::getById($build, $GLOBALS['user'], Access::READ);
             //$smarty->assign($task, $o); // Register for s
             if (!$o instanceof Build_SpecialTaskInterface) {
                 SystemEvent::raise(SystemEvent::ERROR, "Unexisting special task ID. [PID={$GLOBALS['project']->getId()}] [BUILD={$build->getId()}] [TASK={$task}] [TASKID={$build->getId()}]", __METHOD__);
                 continue;
             }
             $viewData = $o->getViewData();
             if (is_array($viewData)) {
                 foreach ($viewData as $key => $value) {
                     $smarty->assign($key, $value);
                 }
             }
             $o = null;
             unset($o);
         }
     }
     // Last assignments
     $smarty->assign('project_build', $build);
     $smarty->display('includes/buildHistoryRev.inc.tpl');
 }
开发者ID:rasismeiro,项目名称:cintient,代码行数:72,代码来源:AjaxManager.php


注:本文中的Smarty::setCacheLifetime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。