コード例 #1
0
ファイル: controller.php プロジェクト: kosmosby/medicine-prof
 public static function getInstance($controllerName, $config = array())
 {
     if (!self::$instances) {
         self::$instances = array();
     }
     $controllerName = preg_replace('/[^A-Z0-9_]/i', '', trim($controllerName));
     // Set the controller name
     $className = 'KomentoController' . ucfirst($controllerName);
     if (!isset(self::$instances[$className])) {
         if (!class_exists($className)) {
             jimport('joomla.filesystem.file');
             $controllerFile = KOMENTO_ADMIN_ROOT . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . JString::strtolower($controllerName) . '.php';
             if (JFile::exists($controllerFile)) {
                 require_once $controllerFile;
                 if (!class_exists($className)) {
                     // Controller does not exists, throw some error.
                     JError::raiseError('500', JText::sprintf('Controller %1$s not found', $className));
                 }
             } else {
                 // File does not exists, throw some error.
                 JError::raiseError('500', JText::sprintf('Controller %1$s.php not found', $controllerName));
             }
         }
         self::$instances[$className] = new $className();
     }
     return self::$instances[$className];
 }