Php/Smarty/smarty5のソースを表示
←
Php/Smarty/smarty5
ナビゲーションに移動
検索に移動
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
==smarty5のダウンロード== https://github.com/smarty-php/smarty/releases/tag/v5.8.0 ==smarty4から5へ== ===setterへ=== 修正前 <pre> $smarty->cache_dir = '/path/to/cache'; $smarty->template_dir = '/path/to/templates'; $smarty->compile_dir = '/path/to/templates_c'; $smarty->left_delimiter = '{{'; $smarty->right_delimiter = '}}'; </pre> 修正後 <pre> $smarty->setCacheDir('/path/to/cache'); $smarty->setTemplateDir('/path/to/templates'); $smarty->setCompileDir('/path/to/templates_c'); $smarty->setLeftDelimiter('{{'); $smarty->setRightDelimiter('}}'); </pre> ===getterへ=== 修正前 <pre> $smarty->template_dir; $smarty->compile_dir; $smarty->cache_dir; $smarty->left_delimiter; $smarty->right_delimiter; </pre> 修正後 <pre> $smarty->getTemplateDir(); $smarty->getCompileDir(); $smarty->getCacheDir(); $smarty->getLeftDelimiter(); $smarty->getRightDelimiter(); </pre> ===use必須=== new Smartyなどで、Smartyを使ってる箇所に以下を追加 use Smarty\Smarty; ===pluginsの場所を変える=== 修正前 smarty-4.5.6/libs/plugins', 修正後 smarty-5.8.0/plugins', ===templateで、modifierのescapeが使えない対応=== エラー詳細 <pre> Fatal error: Uncaught Smarty\CompilerException: Syntax error in template "<h2>{{$message|escape:'html'}}</h2>" unknown modifier 'escape' in / </pre> 対応方法 <pre> $this->setPluginsDir([ APPLICATION_PATH . '/../library/smarty-5.8.0/plugins' ]); </pre> plugins/modifier.escape.php を追加 <pre> <?php /** * Smarty escape modifier * Usage: {$var|escape:'html'} */ function smarty_modifier_escape($string, $type = 'html') { switch ($type) { case 'html': return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); case 'url': return rawurlencode($string); default: return $string; } } </pre> ===templateで、modifierのrandが使えない対応=== エラー詳細 <pre> Fatal error: Uncaught Smarty\CompilerException: Syntax error in template "file:ad.tpl" on line 8 "{{assign var="rand1000" value=1|rand:1000}}" unknown modifier 'rand' </pre> 対応方法 plugins/modifier.rand.php を追加 <pre> <?php function smarty_modifier_rand(...$args) { if (count($args) == 1) { return rand(0, $args[0]); } if (count($args) >= 2) { return rand($args[0], $args[1]); } return rand(); } </pre> ===templateで、modifierのdefaultが使えない対応=== エラー詳細 <pre> Message: Syntax error in template "{{include file="parts/hoge.tpl" request=$request piyo=$piyo|default:''}}" Smarty\CompilerException </pre> 対応方法 plugins/modifier.default.php を追加 <pre> <?php function smarty_modifier_default($value, $default = '') { if ($value === null || $value === '' || $value === false) { return $default; } return $value; } </pre> ===templateで、modifierのdate_formatが使えない対応=== エラー詳細 <pre> Syntax error in template "{{if $smarty.now|date_format:'%Y-%m-%d'<='2014-11-30'}}" unknown modifier 'date_format' </pre> 対応方法 plugins/modifier.date_format.php を追加 <pre> <?php function smarty_modifier_date_format($timestamp, $format = '%Y-%m-%d') { if (!$timestamp) { return ''; } // strftime互換変換 $format = str_replace( ['%Y','%m','%d','%H','%M','%S'], ['Y','m','d','H','i','s'], $format ); if (!is_numeric($timestamp)) { $timestamp = strtotime($timestamp); } return date($format, $timestamp); } </pre> ===templateで、modifierのreplaceが使えない対応=== エラー詳細 <pre> Syntax error in template "" unknown modifier 'replace' </pre> 対応方法 plugins/modifier.replace.php を追加 <pre> <?php function smarty_modifier_replace($string, $search, $replace = '') { return str_replace($search, $replace, $string); } </pre> ===templateで、modifierのurlencodeが使えない対応=== エラー詳細 <pre> Syntax error in template "" unknown modifier 'urlencode' </pre> 対応 plugins/modifier.urlencodephp を追加 <pre> <?php function smarty_modifier_urlencode($string) { return urlencode($string); } </pre> ===templateで、modifierのmb_strimwidthが使えない対応=== エラー詳細 <pre> Syntax error in template "{{$surename|mb_strimwidth:0:40}" unknown modifier 'mb_strimwidth' </pre> 対応 plugins/modifier.mb_strimwidth.php を追加 <pre> <?php function smarty_modifier_mb_strimwidth($string, $start, $width, $trimmarker = '', $encoding = 'UTF-8') { return mb_strimwidth($string, $start, $width, $trimmarker, $encoding); } </pre> ===templateで、functionのmathが使えない対応=== エラー詳細 <pre> Fatal error: Uncaught Smarty\CompilerException: Syntax error in template "file:ad.tpl" on line 1 "{{math equation="rand(1,1000)" assign="rand"}}" unknown tag 'math' in / </pre> 対応方法 plugins/function.math.php を追加 <pre> <?php function smarty_function_math($params, $smarty) { if (!isset($params['equation'])) { return ''; } $equation = $params['equation']; // 非常に簡易な処理(今回の rand 用) if (preg_match('/rand\((\d+),(\d+)\)/', $equation, $m)) { $result = rand((int)$m[1], (int)$m[2]); } else { return ''; } if (isset($params['assign'])) { $smarty->assign($params['assign'], $result); return; } return $result; } </pre> ===templateで、functionのinsertが使えない対応=== エラー詳細 <pre> Syntax error in template "{{insert name="getHoge"}}" unknown tag 'insert' Smarty\CompilerException </pre> 対応方法 plugins/function.insert.php を追加 <pre> <?php function smarty_function_insert($params, $smarty) { if (!isset($params['name'])) { return ''; } $func = 'smarty_insert_' . $params['name']; if (function_exists($func)) { return $func($params, $smarty); } return ''; } </pre> そのまま作ったinsert関数とテンプレが使える <pre> function smarty_insert_getHoge($params, &$smarty) { return "hogehoge"; } </pre> tpl <pre> {{insert name="getHoge"}} </pre> ===templateで、if preg_matchが使えない対応=== エラー詳細 <pre> Syntax error in template "{{if preg_match("/_fuga$/", $request.code)}}" unknown modifier 'preg_match' Smarty\CompilerException </pre> 対応方法 plugins/modifier.preg_match.php を追加。ちなみに、smarty3,4,5で使える。 <pre> <?php function smarty_modifier_preg_match($string, $pattern) { return preg_match($pattern, $string); } </pre> 修正前 <pre> {{if preg_match("/_fuga$/", $request.code)}} {{elseif preg_match("/\.hoge/", $itaurl)}} {{elseif preg_match("/\.piyo/", $itaurl)}} {{/if}} </pre> 修正後 <pre> {{if $request.code|preg_match:"/_fuga$/"}} {{elseif $itaurl|preg_match:"/\.hoge/"}} {{elseif $itaurl|preg_match:"/\.piyo/"}} {{else}} {{/if}} </pre> ===templateで、countが使えない対応=== エラー詳細 <pre> Syntax error in template "{{if count($genres) > 0}}" unknown modifier 'count' Smarty\CompilerException </pre> 対応方法 plugins/modifier.count.php を追加。 <pre> <?php function smarty_modifier_count($value) { if (is_array($value) || $value instanceof Countable) { return count($value); } return 0; } </pre> 修正前 <pre> {{if count($genres) > 0}} </pre> 修正後 <pre> {{if $genres|count > 0}} </pre> ===templateで、substrが使えない対応=== エラー詳細 <pre> Syntax error in template "{{$genre.created|substr:0:16}}" unknown modifier 'substr' Smarty\CompilerException </pre> 対応方法 plugins/modifier.substr.php を追加。 <pre> <?php function smarty_modifier_substr($string, $start, $length = null) { if ($length === null) { return substr($string, $start); } return substr($string, $start, $length); } </pre> ===templateで、get_classが使えない対応=== 修正前 <pre> // ErrorController.php $this->view->exception = $errors->exception; // error.tpl {{$exception|get_class}} </pre> 修正後 <pre> // ErrorController.php $this->view->exception = $errors->exception; $this->view->exception_class = get_class($errors->exception); // error.tpl <b>Class:</b> {{$exception_class}} </pre> ===getPluginsDir()やsetPluginsDir()について=== smarty5では、getPluginsDirがdeprecatedで、[]の空配列が、強制になってって使えなくなってる。 ===getTemplateDirなど=== getSmarty()を経由する必要がある。 修正前 $smarty->getTemplateDir(); 修正後 $smarty->getSmarty()->getTemplateDir();
Php/Smarty/smarty5
に戻る。
ナビゲーション メニュー
個人用ツール
ログイン
名前空間
ページ
議論
日本語
表示
閲覧
ソースを閲覧
履歴表示
その他
検索
案内
プログラムメモ
php
flutter
java
android
kotlin
ios
unity
unrealengine
javascript
mysql
sqlite
postgresql
oracle
mroonga
mongodb
flash
electron
cocos2dx
titanium
cpp
ruby
perl
python
accessメモ
rss
html
monaca
cordova
golang
blender
セキュリティ
テストツール
サーバメモ
linux
dotnet
apacheメモ
htaccessメモ
subversion
git
仮想サーバ
ansible
sendgrid
xampp
cacti
mecab
faces
flashpolicyd
fcs
jenkins
運用
デザインメモ
css
ユーザビリティ
ux
サービスメモ
twitter
facebook
instagram
mixi
セカンドライフ
通信ログ横取り
google
ustream
aws
gcp
plesk
azure
vps
AI
その他サービス
便利系メモ
SEO
モバイル
抽象変数名
DDD
クライアント
firefox
chrome
pgp
windows
mac
jmetar
Thunderbird
excel
libreoffice
vpnclient
doxygen
VisualStudioCode
fastlane
metaquest
cmsメモ
mediawiki
pukiwiki
wordpress
その他
資格
IT用語
pvを稼ぐ方法
将棋プログラム
その他
ログイン
ページ内
メインページ
最近の更新
人気のページ
問い合わせ
ツール
リンク元
関連ページの更新状況
ページ情報