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


PHP Smarty::setCaching方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:noumenia,项目名称:nyx,代码行数:29,代码来源:templatefactory.inc.php

示例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;
 }
开发者ID:skillfish,项目名称:zf3-smarty-module,代码行数:26,代码来源:RendererFactory.php

示例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;
     }
 }
开发者ID:noumenia,项目名称:aetolos,代码行数:36,代码来源:templatefactory.inc.php

示例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];
 }
开发者ID:ChangAiQing,项目名称:framework_app,代码行数:16,代码来源:resource.class.php

示例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);
 }
开发者ID:agrafix,项目名称:managerslife,代码行数:20,代码来源:Site_Rss.class.php

示例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);
开发者ID:jackycgq,项目名称:bzfshop,代码行数:31,代码来源:bootstrap.php

示例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']);
}
开发者ID:Erdou,项目名称:Rikiki-MVC,代码行数:31,代码来源:init.php

示例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';
开发者ID:noncepool,项目名称:php-mpos,代码行数:26,代码来源:smarty.inc.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;
 }
开发者ID:uab-balticode,项目名称:dpd-shipping-module-prestashop-2,代码行数:15,代码来源:DpdManifestRender.php

示例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;
开发者ID:RhenusoneRosalia,项目名称:portfolio,代码行数:19,代码来源:smarty.inc.php


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