本文整理汇总了PHP中Smarty::setCaching方法的典型用法代码示例。如果您正苦于以下问题:PHP Smarty::setCaching方法的具体用法?PHP Smarty::setCaching怎么用?PHP Smarty::setCaching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smarty
的用法示例。
在下文中一共展示了Smarty::setCaching方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Create a new template object
* @return object
*/
public static function create()
{
// Try/catch statement
try {
// Smarty installation
$configDir = Config::read('smarty');
// Required Smarty libraries
require_once $configDir . '/libs/Smarty.class.php';
// Smarty v3.1 or newer
$smarty = new Smarty();
$smarty->setTemplateDir(Config::read('pwd') . '/templates/' . Config::read('template'));
$smarty->setCompileDir($configDir . '/templates_c');
$smarty->setCacheDir($configDir . '/cache');
// Disable caching
$smarty->force_compile = true;
$smarty->compile_check = true;
$smarty->setCaching(Smarty::CACHING_OFF);
// Return Smarty object
return $smarty;
} catch (Exception $e) {
Log::error("Error while loading template engine");
// Exception error
return false;
}
}
示例2: __invoke
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $container->get('Configuration');
$config = $config['smarty'];
/** @var $pathResolver \Zend\View\Resolver\TemplatePathStack */
$pathResolver = clone $container->get('ViewTemplatePathStack');
$pathResolver->setDefaultSuffix($config['suffix']);
/** @var $resolver \Zend\View\Resolver\AggregateResolver */
$resolver = $container->get('ViewResolver');
$resolver->attach($pathResolver);
$engine = new \Smarty();
$engine->setCompileDir($config['compile_dir']);
$engine->setEscapeHtml($config['escape_html']);
$engine->setTemplateDir($pathResolver->getPaths()->toArray());
$engine->setCaching($config['caching']);
$engine->setCacheDir($config['cache_dir']);
$engine->addPluginsDir($config['plugins_dir']);
if (file_exists($config['config_file'])) {
$engine->configLoad($config['config_file']);
}
$renderer = new Renderer();
$renderer->setEngine($engine);
$renderer->setSuffix($config['suffix']);
$renderer->setResolver($resolver);
return $renderer;
}
示例3: 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;
}
}
示例4: getView
public static function getView($key = 'default')
{
if (isset(self::$viewResMap[$key])) {
return self::$viewResMap[$Key];
}
require_once FILE . "/component/smarty-3.1.24/libs/Smarty.class.php";
$view = new Smarty();
$view->setTemplateDir(FILE . cfg_template::$template_dir . $key);
$view->setCompileDir(FILE . '/data/' . $key . cfg_template::$compile_dir);
$view->setCacheDir(FILE . '/data/' . $key . cfg_template::$cache_dir);
$view->setCaching(cfg_template::$caching);
$view->setLeftDelimiter(cfg_template::$left_delimiter);
$view->setRightDelimiter(cfg_template::$right_delimiter);
self::$viewResMap[$key] = $view;
return self::$viewResMap[$key];
}
示例5: show_News
public function show_News()
{
header("Content-Type: application/rss+xml; charset=UTF-8");
$tpl = new Smarty();
$tpl->cache_lifetime = 3600 * 24;
$tpl->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
$cacheID = 'rssFeed';
if (!$tpl->isCached('rss.xml', $cacheID)) {
$items = array();
$dbItems = R::find('homepage_posts', ' 1=1 ORDER BY id DESC LIMIT 15');
foreach ($dbItems as $item) {
$author = R::relatedOne($item, 'user');
$items[] = array('title' => $item->title, 'link' => $item->link == '' ? APP_WEBSITE . APP_DIR : $item->link, 'description' => $item->content, 'author' => $author->username, 'date' => date("D, d M Y H:i:s O", $item->time));
}
$tpl->assign('items', $items);
$tpl->assign('gentime', date("D, d M Y H:i:s O"));
$tpl->assign('link', APP_WEBSITE . APP_DIR);
}
$tpl->display('rss.xml', $cacheID);
}
示例6: smarty_helper_security_output_filter
// 初始化 smarty 模板引擎
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);
示例7: 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']);
}
示例8: exit
<?php
$defflip = !cfip() ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
$debug->append('Loading Smarty libraries', 2);
define('SMARTY_DIR', INCLUDE_DIR . '/smarty/libs/');
// Include the actual smarty class file
include SMARTY_DIR . 'Smarty.class.php';
// We initialize smarty here
$debug->append('Instantiating Smarty Object', 3);
$smarty = new Smarty();
// Assign our local paths
$debug->append('Define Smarty Paths', 3);
$smarty->template_dir = TEMPLATE_DIR . '/' . THEME . '/';
$smarty->compile_dir = TEMPLATE_DIR . '/compile/' . THEME . '/';
$smarty_cache_key = md5(serialize($_REQUEST) . serialize(@$_SESSION['USERDATA']['id']));
// Optional smarty caching, check Smarty documentation for details
if ($config['smarty']['cache']) {
$debug->append('Enable smarty cache');
$smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED);
$smarty->cache_lifetime = $config['smarty']['cache_lifetime'];
$smarty->cache_dir = TEMPLATE_DIR . '/cache/' . THEME;
$smarty->escape_html = true;
$smarty->use_sub_dirs = true;
}
// Load custom smarty plugins
require_once INCLUDE_DIR . '/lib/smarty_plugins/function.acl.php';
示例9: getManifestFooterHTML
/**
* Render Manifest footer template
*
* @param array $variables some footer template variables
* @return string HTML content of Manifest footer
*/
private static function getManifestFooterHTML($variables = array())
{
$smarty = new Smarty();
$smarty->setCaching(false);
$smarty->assign($variables);
$manifestFooter = self::getPath('') . 'views/templates/admin/manifest/footer.tpl';
$manifestFooterContent = $smarty->fetch($manifestFooter);
return $manifestFooterContent;
}
示例10: Smarty
<?php
# get the smarty lib
require SMARTY_PATH;
# define the cache dir
define('CACHE_DIR', '/var/www/cache');
#create smarty object
$oSmarty = new Smarty();
# assign smarty settings
if (CRON) {
$oSmarty->setTemplateDir('/var/www/rhenusonerosalia.com/public_html/templates');
} else {
$oSmarty->setTemplateDir($_SERVER['DOCUMENT_ROOT'] . '/templates');
}
$oSmarty->setCompileDir(CACHE_DIR . '/templates_compiled');
$oSmarty->setCacheDir(CACHE_DIR . '/templates_cache');
$oSmarty->setCaching(CACHING_OFF);
$oSmarty->caching = 0;
$oSmarty->force_compile = true;