當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。