本文整理匯總了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;
}
}
示例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;
示例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']);
}
示例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'] . '/');
示例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');
}