From a6a101600636421490c2c4cb8c23a2297cc1f021 Mon Sep 17 00:00:00 2001 From: Darren-Lee Joseph Date: Sat, 17 Oct 2015 18:17:04 +0100 Subject: [PATCH] refactor code to make use of renderWith method... best practice --- code/UtilityPage.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/code/UtilityPage.php b/code/UtilityPage.php index aa1f853..a6e1fde 100644 --- a/code/UtilityPage.php +++ b/code/UtilityPage.php @@ -132,14 +132,13 @@ public function getCMSFields() { */ public static function get_top_level_templates() { - $ss_templates_array = array(); //initialise empty array + $ss_templates_array = array(); $current_theme_path = THEMES_PATH . '/' . Config::inst()->get('SSViewer', 'theme'); //theme directories to search $search_dir_array = array( MAINTENANCE_MODE_PATH .'/templates', $current_theme_path .'/templates' - //$current_theme_path .'/templates/Layout' //we only want top level templates ); foreach($search_dir_array as $directory) { @@ -170,12 +169,17 @@ public static function get_top_level_templates() { */ class UtilityPage_Controller extends Page_Controller { - public $templates; //required for template overrides + private static $url_handlers = array( + '*' => 'index' + ); private static $allowed_actions = array(); public function init() { parent::init(); + } + + public function index() { $config = $this->SiteConfig(); @@ -184,10 +188,12 @@ public function init() { return $this->redirect(BASE_URL); //redirect to home page } + $this->response->setStatusCode($this->ErrorCode); + if($this->dataRecord->RenderingTemplate) { - $this->templates['index'] = array($this->dataRecord->RenderingTemplate, 'Page'); + return $this->renderWith(array($this->dataRecord->RenderingTemplate, 'Page')); } - $this->response->setStatusCode($this->ErrorCode); + return array(); } }