1. 程式人生 > >thinkcmf5 模板版變量的加載過程

thinkcmf5 模板版變量的加載過程

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 模板版變量的加載過程