facebook twitter hatena line email

「Php/Smarty/2から3へ移行」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(memcacheなどにエンジンを変更する場合)
(memcacheなどにエンジンを変更する場合)
行47: 行47:
 
smarty3
 
smarty3
 
  $smartyMemcache = new Smarty_CacheResource_Memcache($cacheInstance);
 
  $smartyMemcache = new Smarty_CacheResource_Memcache($cacheInstance);
  $smarty->caching_type = 'memcache';
+
  $smarty->registerCacheResource('memcache', $smartyMemcache); // memcache登録
  $smarty->registerCacheResource('memcache', $smartyMemcache);
+
  $smarty->caching_type = 'memcache'; // cache方法にmemcacheを選択
  
 
参考:https://github.com/koriym/Smarty3/blob/master/demo/plugins/cacheresource.memcache.php
 
参考:https://github.com/koriym/Smarty3/blob/master/demo/plugins/cacheresource.memcache.php

2015年8月5日 (水) 19:53時点における版

基本的なところはここを見る

http://nplll.com/archives/2010/04/smarty2_3.php

自分メモはこちら

$smarty->template_dirがpublicからprivateへ

$smarty->setTemplateDir($template_dir); 設定
$smarty->getTemplateDir(); 取得

$smarty->compile_dirがpublicからprivateへ

$smarty->setCompileDir(compile_dir); 追加設定
$smarty->getCompileDir(); 取得

$smarty->cache_dirがpublicからprivateへ

$smarty->setCacheDir(compile_dir); 追加設定
$smarty->getCacheDir(); 取得

$smarty->plugins_dir[]がpublicからprivateへ

$smarty->addPluginsDir($plugins_dir); 追加設定
$smarty->getPluginsDir(); 取得

カスタム設定例

class MySmarty extends Smarty
{
  public function __construct() {
    $this->debugging = false;
    $this->left_delimiter = '{{';
    $this->right_delimiter = '}}';
    $this->setTemplateDir(__DIR__ . "/../views/templates");
    $this->setCompileDir(__DIR__ . "/../views/templates_c");
    $this->setCacheDir(__DIR__ . "/../views/cache/");
    $this->addPluginsDir(SMARTY_PLUGINS_DIR);
    $this->addPluginsDir(__DIR__ . '/smartyPlugins');
    $this->Smarty();
  }
}

phpタグを使用してコード内でphpを実行する場合

Smarty.class.phpでなくSmartyBCを使う&PHP_ALLOWを設定する

require_once __DIR__ . '/smarty/libs/SmartyBC.class.php';
$smarty = new SmartyBC();
$smarty->php_handling = Smarty::PHP_ALLOW;

memcacheなどにエンジンを変更する場合

smarty2

$smarty->cache_handler_func = array($smartyMemcache, 'cacheHandler');

smarty3

$smartyMemcache = new Smarty_CacheResource_Memcache($cacheInstance);
$smarty->registerCacheResource('memcache', $smartyMemcache); // memcache登録
$smarty->caching_type = 'memcache'; // cache方法にmemcacheを選択

参考:https://github.com/koriym/Smarty3/blob/master/demo/plugins/cacheresource.memcache.php