From c9d58d45a057e5b713927aa56dbb2e2565078830 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Tue, 27 Sep 2011 15:20:30 +0000 Subject: [PATCH] // change to Controller workflow --- classes/AdminController.php | 39 +++++++++++++------------------------ classes/Controller.php | 29 +++++++++++++++++++++++---- classes/FrontController.php | 28 ++++++++++++-------------- 3 files changed, 50 insertions(+), 46 deletions(-) diff --git a/classes/AdminController.php b/classes/AdminController.php index 77a324601..d907111b4 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -111,37 +111,30 @@ class AdminControllerCore extends Controller return (!empty($token) AND $token === $this->token); } - public function action() + public function postProcess() { - if (!$this->ajax) - { - $this->postProcess(); - $this->setMedia(); - $this->initHeader(); - $this->initFooter(); - //$adminObj->displayConf(); - //$adminObj->displayErrors(); - } - else + if ($this->ajax) { // from ajax-tab.php - if(method_exists($this,'ajaxPreprocess')) + if (method_exists($this, 'ajaxPreprocess')) $this->ajaxPreProcess(); $action = Tools::getValue('action'); // no need to use displayConf() here - if (!empty($action) AND method_exists($this, 'ajaxProcess'.Tools::toCamelCase($action)) ) + if (!empty($action) && method_exists($this, 'ajaxProcess'.Tools::toCamelCase($action))) $this->{'ajaxProcess'.Tools::toCamelCase($action)}(); else $this->ajaxProcess(); - // @TODO We should use a displayAjaxError - $this->displayErrors(); - if (!empty($action) AND method_exists($this, 'displayAjax'.Tools::toCamelCase($action)) ) - $this->{'displayAjax'.$action}(); - else - $this->displayAjax(); - + // @TODO We should use a displayAjaxError + /*$this->displayErrors(); + if (!empty($action) && method_exists($this, 'displayAjax'.Tools::toCamelCase($action))) + $this->{'displayAjax'.$action}(); + else + $this->displayAjax(); */ + } + else + { } } @@ -549,10 +542,4 @@ class AdminControllerCore extends Controller { p($this->_errors); } - - public function postProcess() - { - - } - } diff --git a/classes/Controller.php b/classes/Controller.php index 081e62aca..2e45e1c8a 100644 --- a/classes/Controller.php +++ b/classes/Controller.php @@ -73,7 +73,7 @@ abstract class ControllerCore /** * Do the page treatment : post process, ajax process, etc. */ - abstract public function action(); + abstract public function postProcess(); /** * Display page view @@ -111,12 +111,18 @@ abstract class ControllerCore public function run() { $this->init(); - $this->action(); + $this->postProcess(); + if ($this->displayHeader) + { + $this->setMedia(); + $this->initHeader(); + } + $this->initContent(); + if ($this->displayFooter) + $this->initFooter(); if ($this->ajax) - { $this->displayAjax(); - } else $this->display(); } @@ -135,7 +141,22 @@ abstract class ControllerCore { $this->template = $template; } + + /** + * Assign smarty variables for the page header + */ + abstract public function initHeader(); + + /** + * Assign smarty variables for the page main content + */ + abstract public function initContent(); + /** + * Assign smarty variables for the page footer + */ + abstract public function initFooter(); + /** * Add a new stylesheet in page header. * diff --git a/classes/FrontController.php b/classes/FrontController.php index 91646f920..9dc9f84a6 100755 --- a/classes/FrontController.php +++ b/classes/FrontController.php @@ -87,6 +87,12 @@ class FrontControllerCore extends Controller exit(); } + if ($this->ajax) + { + $this->displayHeader(false); + $this->displayFooter(false); + } + ob_start(); // Switch language if needed and init cookie language @@ -335,7 +341,7 @@ class FrontControllerCore extends Controller $this->context->controller = $this; } - public function action() + public function postProcess() { /*// For retrocompatibility with versions before 1.5, preProcess support will be removed on next release if (method_exists(get_class($this), 'preProcess')) @@ -347,25 +353,15 @@ class FrontControllerCore extends Controller $this->preProcess(); } }*/ - - if ($this->ajax) - { - $this->displayHeader(false); - $this->displayFooter(false); - } - $this->preProcess(); - - // Prepare generation of page display - $this->processHeader(); - $this->process(); - $this->processFooter(); + + //$this->preProcess(); } public function preProcess() { } - public function process() + public function initContent() { } @@ -508,7 +504,7 @@ class FrontControllerCore extends Controller $this->addCSS(_THEME_CSS_DIR_.'rtl.css'); } - public function processHeader() + public function initHeader() { // P3P Policies (http://www.w3.org/TR/2002/REC-P3P-20020416/#compact_policies) header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"'); @@ -548,7 +544,7 @@ class FrontControllerCore extends Controller $this->context->smarty->assign('js_files', array_unique($this->js_files)); } - public function processFooter() + public function initFooter() { $this->context->smarty->assign(array( 'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => $this->context->cart)),