Exemple #1
0
 /**
  * KSSystem::getController()
  *
  * @param mixed $name
  * @param mixed $config
  * @return
  */
 public static function getController($name, $ext_name = null, $config = array())
 {
     if (empty(self::$ext_name)) {
         self::setGlobalVar('ext_name');
     }
     if (empty(self::$ext_name_com)) {
         self::setGlobalVar('ext_name_com');
     }
     if (!empty($ext_name)) {
         $ext_name_com = 'com_' . $ext_name;
         if (JFactory::getApplication()->isAdmin()) {
             $maincontrollerFile = JPATH_ADMINISTRATOR . DS . 'components' . DS . $ext_name_com . DS . 'controller.php';
         } else {
             $maincontrollerFile = JPATH_SITE . DS . 'components' . DS . $ext_name_com . DS . 'controller.php';
         }
         if (file_exists($maincontrollerFile)) {
             require_once $maincontrollerFile;
         }
     } else {
         $ext_name = self::$ext_name;
         $ext_name_com = self::$ext_name_com;
     }
     jimport('joomla.application.component.controller');
     $controllerFile = JPATH_SITE . DS . 'components' . DS . $ext_name_com . DS . 'controllers' . DS . $name . '.php';
     $adminControllerFile = JPATH_ADMINISTRATOR . DS . 'components' . DS . $ext_name_com . DS . 'controllers' . DS . $name . '.php';
     if (file_exists($controllerFile)) {
         require_once $controllerFile;
     } elseif (file_exists($adminControllerFile)) {
         require_once $adminControllerFile;
     } else {
         JControllerLegacy::addIncludePath(JPATH_SITE . DS . 'components' . DS . $ext_name_com . DS . 'controllers');
     }
     $controller_name = ucfirst($ext_name) . 'Controller';
     $controller_name = $controller_name . $name;
     $controller = new $controller_name();
     return $controller;
 }