FuelPHP Bin
theme_controller
<?php namespace Sakila\Controller\Backend; class Themed extends \Sakila\Controller\Backend\Base { protected $_current_theme = null; protected $_theme_cfg = array(); private $__base_tpl_relative_path = null; public function before() { parent::before(); log_if_development(\Fuel::L_INFO, "Custom THEMED Controller {" . __CLASS__ ."} used !!!", __METHOD__); ///////////////////////////////////////////////////////////////////////////// //TODO: use some ThemeService or ThemeProvider for auto-initializing theme // ///////////////////////////////////////////////////////////////////////////// //load backend-theme config $this->_theme_cfg = \Config::load('themes_backend', 'admin_theme', false, true); //init theme.... $this->theme = \Theme::instance('admin_theme', $this->_theme_cfg); $this->_current_theme = $this->theme->active(); $this->__base_tpl_relative_path = '..'.DS.'themes'.DS.'back-end'.DS.$this->_current_theme['name'].DS; $this->theme->get_info('settings.log_theme_and_asset_creation') and logger(\Fuel::L_INFO, 'Backend theme <'.$this->_current_theme['name'].'> created.', __METHOD__); // theme->set_template() tries to load from APPPATH/views. Since it's not an option for me, I cheat and user relative path like: // APPATH/views/../themes/themes/back-end/<theme_name>/<mater_tpl_from_theme_config> $this->theme->set_template( $this->__base_tpl_relative_path . $this->theme->get_info('master_tpl').$this->_theme_cfg['view_ext']); $this->template->set_global('theme_info', $this->theme->get_info()); ////////////////// // theme assets // ////////////////// //Setting theme_assets to themes specific paths and custom subdirs (if any) if($this->theme->asset instanceof \Asset_Instance) { /* new Assets_Instance needs a configuration */ $theme_assets_cfg = array( /* override default value */ 'paths' => array( $this->_theme_cfg['assets_folder'] . '/' . $this->_current_theme['name'] ), // 'fail_silently' => true, ); //if there are any custom assets subfolders/types, use them instead of default css/, js/ and img/ if( $this->theme->get_info('custom_assets_subdirs', false ) ) { $custom_assets_subdirs_paths = array( 'img_dir' => $this->theme->get_info('custom_assets_subdirs.img_dir', null), 'css_dir' => $this->theme->get_info('custom_assets_subdirs.css_dir', null), 'js_dir' => $this->theme->get_info('custom_assets_subdirs.js_dir', null), ); //merging $theme_assets_cfg with custom assets subdirs settings from $custom_assets_subdirs_paths $theme_assets_cfg = \Arr::merge($theme_assets_cfg, $custom_assets_subdirs_paths); } ///////////////// // REFACTOR // ///////////////// //instantiate new \Assets_Instance and make it avialable under alias 'admin_theme' -> for naming simplicity in templates $this->theme->asset = \Asset::forge('admin_theme', $theme_assets_cfg); $this->theme->get_info('settings.log_theme_and_asset_creation') and logger(\Fuel::L_INFO, 'Theme\'s Asset_Instance created and accessable under \'admin_theme\'', __METHOD__); } $this->template = $this->theme->get_template(); /////////////////////// // setting up layout // /////////////////////// //1 - topbar //2 - sidebar //3 - maincontent $this->theme->set_partial('layout_topnavbar', 'partials/layout/topnavbar'); $this->theme->set_partial('layout_sidebar', 'partials/layout/sidebar'); // $this->theme->set_partial('layout_content', 'partials/layout/content'); } /** * keep the after() as standard as possible to allow custom responses from actions */ public function after($response) { // If no response object was returned by the action, if (empty($response) or ! $response instanceof Response) { // render the defined template $response = \Response::forge($this->theme->render()); } return parent::after($response); } }