// Refacto of controllers PART 2
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8802 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+13
-3
@@ -25,6 +25,9 @@
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
*/
|
||||
abstract class ControllerCore
|
||||
{
|
||||
/**
|
||||
@@ -57,6 +60,11 @@ abstract class ControllerCore
|
||||
*/
|
||||
protected $displayFooter = false;
|
||||
|
||||
/**
|
||||
* @var bool If ajax parameter is detected in request, set this flag to true
|
||||
*/
|
||||
protected $ajax = false;
|
||||
|
||||
/**
|
||||
* Initialize the page
|
||||
*/
|
||||
@@ -64,7 +72,6 @@ abstract class ControllerCore
|
||||
|
||||
/**
|
||||
* Do the page treatment : post process, ajax process, etc.
|
||||
* Enter description here ...
|
||||
*/
|
||||
abstract public function action();
|
||||
|
||||
@@ -92,16 +99,19 @@ abstract class ControllerCore
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->displayHeader(true);
|
||||
$this->displayFooter(true);
|
||||
$this->context = Context::getContext();
|
||||
$this->ajax = Tools::getValue('ajax') || Tools::isSubmit('ajax');
|
||||
}
|
||||
|
||||
/**
|
||||
* Start controller process
|
||||
* Start controller process (this method shouldn't be overriden !)
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->init();
|
||||
$this->action();
|
||||
$this->action(array('titi'), $this);
|
||||
$this->display();
|
||||
}
|
||||
|
||||
|
||||
+12
-5
@@ -236,8 +236,8 @@ class DispatcherCore
|
||||
$this->getController();
|
||||
$controllers = Dispatcher::getControllers($this->controller_directories);
|
||||
|
||||
if (!$this->controller || $this->controller == 'index')
|
||||
$this->controller = (defined('_PS_ADMIN_DIR_')) ? 'adminhome' : 'index';
|
||||
if (!$this->controller)
|
||||
$this->controller = $this->default_controller;
|
||||
|
||||
// For retrocompatibility with admin/tabs/ old system
|
||||
if (isset($controllers[$this->controller]) && defined('_PS_ADMIN_DIR_') && file_exists(_PS_ADMIN_DIR_.'/tabs/'.$controllers[$this->controller].'.php'))
|
||||
@@ -251,7 +251,14 @@ class DispatcherCore
|
||||
$this->controller = $this->controller_not_found;
|
||||
|
||||
// Instantiate controller
|
||||
Controller::getController($controllers[$this->controller])->run();
|
||||
try
|
||||
{
|
||||
Controller::getController($controllers[$this->controller])->run();
|
||||
}
|
||||
catch (PrestashopException $e)
|
||||
{
|
||||
$e->displayMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -448,8 +455,8 @@ class DispatcherCore
|
||||
if ($this->use_routes && !$controller)
|
||||
{
|
||||
if (!$this->request_uri)
|
||||
return 'pagenotfound';
|
||||
$controller = 'index';
|
||||
return $this->controller_not_found;
|
||||
$controller = $this->default_controller;
|
||||
|
||||
// Add empty route as last route to prevent this greedy regexp to match request uri before right time
|
||||
if ($this->empty_route)
|
||||
|
||||
+12
-17
@@ -333,28 +333,27 @@ class FrontControllerCore extends Controller
|
||||
$this->context->cart = $cart;
|
||||
$this->context->currency = $currency;
|
||||
$this->context->controller = $this;
|
||||
|
||||
$this->displayHeader();
|
||||
$this->displayFooter();
|
||||
}
|
||||
|
||||
public function action()
|
||||
{
|
||||
// For retrocompatibility
|
||||
if (method_exists($this, 'preProcess'))
|
||||
/*// For retrocompatibility with versions before 1.5, preProcess support will be removed on next release
|
||||
if (method_exists(get_class($this), 'preProcess'))
|
||||
{
|
||||
Tools::displayAsDeprecated('Method preProcess() is deprecated in controllers, use method postProcess() instead');
|
||||
$this->preProcess();
|
||||
}
|
||||
$reflection = new ReflectionClass($this);
|
||||
if (!in_array($reflection->getMethod('preProcess')->class, array('FrontController', 'FrontControllerCore')))
|
||||
{
|
||||
Tools::displayAsDeprecated('Method preProcess() is deprecated in controllers, use method postProcess() instead');
|
||||
$this->preProcess();
|
||||
}
|
||||
}*/
|
||||
|
||||
if (Tools::getValue('ajax') == 'true')
|
||||
if ($this->ajax)
|
||||
{
|
||||
$this->displayHeader(false);
|
||||
$this->displayFooter(false);
|
||||
$this->ajaxProcess();
|
||||
}
|
||||
else
|
||||
$this->postProcess();
|
||||
$this->preProcess();
|
||||
|
||||
// Prepare generation of page display
|
||||
$this->processHeader();
|
||||
@@ -362,11 +361,7 @@ class FrontControllerCore extends Controller
|
||||
$this->processFooter();
|
||||
}
|
||||
|
||||
public function ajaxProcess()
|
||||
{
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
public function preProcess()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user