ace decode value 过程 rom gets foreach span fec
在 HomeBaseController.php 的 fech方法
$more = $this->getThemeFileMore($template);
用
- echo ThemeModel: :getLastSql();输出sql语句:SELECT`more`FROM`cmf_theme_file`WHERE`theme` = ‘w0s‘AND(`is_public` = 1 OR`file` = ‘portal / index‘)获取了声明公共配置和当前模板文件的模板配置。
- 可见,不管当前theme下那个模板文件配置,只要is_public = 1,就可以加载vars和widgets。
- /**
- * 获取模板文件变量
- * @param string $file
- * @param string $theme
- * @return array
- */
- private
- function getThemeFileMore($file, $theme = "") {
- //TODO 增加缓存
- $theme = empty($theme) ? cmf_get_current_theme() : $theme;
- // 调试模式下自动更新模板
- if (APP_DEBUG) {
- $themeModel = new ThemeModel();
- $themeModel - >updateTheme($theme);
- }
- $themePath = config(‘cmf_theme_path‘);
- $file = str_replace(‘\\‘, ‘ / ‘, $file);
- $file = str_replace(‘ //‘, ‘/‘, $file);
- $file = str_replace([‘.html‘, ‘.php‘, $themePath.$theme."/"], ‘‘, $file);
- $files = Db: :name(‘theme_file‘) - >field(‘more‘) - >where([‘theme‘ = >$theme]) - >where(function($query) use($file) {
- $query - >where([‘is_public‘ = >1]) - >whereOr([‘file‘ = >$file]);
- }) - >select(); echo ThemeModel: :getLastSql(); $vars = []; $widgets = []; foreach($files as $file) {
- $oldMore = json_decode($file[‘more‘], true);
- if (!empty($oldMore[‘vars‘])) {
- foreach($oldMore[‘vars‘] as $varName = >$var) {
- $vars[$varName] = $var[‘value‘];
- }
- }
- if (!empty($oldMore[‘widgets‘])) {
- foreach($oldMore[‘widgets‘] as $widgetName = >$widget) {
- $widgetVars = [];
- if (!empty($widget[‘vars‘])) {
- foreach($widget[‘vars‘] as $varName = >$var) {
- $widgetVars[$varName] = $var[‘value‘];
- }
- }
- $widget[‘vars‘] = $widgetVars;
- $widgets[$widgetName] = $widget;
- }
- }
- }
- return [‘vars‘ = >$vars, ‘widgets‘ = >$widgets];
- }
thinkcmf5 模板版变量的加载过程
来源: http://www.bubuko.com/infodetail-2323231.html