function dispatch($module = null, $action = null, $parameters = null)
 {
     if (is_null($module)) {
         $defaultModule = Core_Helper::getDefaultModuleName();
         $module = Core_Common::getRequestVar('module', $defaultModule, 'string');
     }
     if (is_null($action)) {
         $action = Core_Common::getRequestVar('action', false);
     }
     if (is_null($parameters)) {
         $parameters = array();
     }
     if (!ctype_alnum($module)) {
         throw new Exception("Invalid module name '{$module}'");
     }
     $controllerClassName = "Module_" . $module . "_Controller";
     /* Check if the plugin has been activated */
     if (!Core_ModuleManager::getInstance()->isModuleActivated($module)) {
         throw new Core_FrontController_PluginDeactivatedException($module);
     }
     // Dynamically create the class
     $controller = new $controllerClassName();
     if ($action === false) {
         $action = $controller->getDefaultAction();
     }
     // Dynamically call the action
     if (!is_callable(array($controller, $action))) {
         throw new Exception("Action not found in {$controllerClassName}::{$action}().");
     }
     try {
         $controller->preDispatch();
         return call_user_func_array(array($controller, $action), $parameters);
     } catch (Core_Access_NoAccessException $e) {
         Core_PostEvent('FrontController.NoAccessException');
     } catch (Exception $e) {
         echo 'Error: ' . $e;
         return null;
     }
 }
Exemple #2
0
 /**
  * Logout the current user
  */
 function logout()
 {
     self::clearSession();
     Core_Helper::redirectToModule(Core_Helper::getDefaultModuleName());
 }