当前位置: 首页>>代码示例>>PHP>>正文


PHP JControllerLegacy::instance方法代码示例

本文整理汇总了PHP中JControllerLegacy::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP JControllerLegacy::instance方法的具体用法?PHP JControllerLegacy::instance怎么用?PHP JControllerLegacy::instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JControllerLegacy的用法示例。


在下文中一共展示了JControllerLegacy::instance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getInstance

 /**
  * Method to get a singleton controller instance.
  *
  * @param   string  $prefix  The prefix for the controller.
  * @param   array   $config  An array of optional constructor options.
  *
  * @return  JControllerLegacy
  *
  * @since   12.2
  * @throws  Exception if the controller cannot be loaded.
  */
 public static function getInstance($prefix, $config = array())
 {
     if (is_object(self::$instance)) {
         return self::$instance;
     }
     $input = JFactory::getApplication()->input;
     // Get the environment configuration.
     $basePath = array_key_exists('base_path', $config) ? $config['base_path'] : JPATH_COMPONENT;
     $format = $input->getWord('format');
     $command = $input->get('task', 'display');
     // Check for array format.
     $filter = JFilterInput::getInstance();
     if (is_array($command)) {
         $command = $filter->clean(array_pop(array_keys($command)), 'cmd');
     } else {
         $command = $filter->clean($command, 'cmd');
     }
     // Check for a controller.task command.
     if (strpos($command, '.') !== false) {
         // Explode the controller.task command.
         list($type, $task) = explode('.', $command);
         // Define the controller filename and path.
         $file = self::createFileName('controller', array('name' => $type, 'format' => $format));
         $path = $basePath . '/controllers/' . $file;
         // Reset the task without the controller context.
         $input->set('task', $task);
     } else {
         // Base controller.
         $type = null;
         $task = $command;
         // Define the controller filename and path.
         $file = self::createFileName('controller', array('name' => 'controller', 'format' => $format));
         $path = $basePath . '/' . $file;
         $backupfile = self::createFileName('controller', array('name' => 'controller'));
         $backuppath = $basePath . '/' . $backupfile;
     }
     // Get the controller class name.
     $class = ucfirst($prefix) . 'Controller' . ucfirst($type);
     // Include the class if not present.
     if (!class_exists($class)) {
         // If the controller file path exists, include it.
         if (file_exists($path)) {
             require_once $path;
         } elseif (isset($backuppath) && file_exists($backuppath)) {
             require_once $backuppath;
         } else {
             throw new InvalidArgumentException(JText::sprintf('JLIB_APPLICATION_ERROR_INVALID_CONTROLLER', $type, $format));
         }
     }
     // Instantiate the class.
     if (class_exists($class)) {
         self::$instance = new $class($config);
     } else {
         throw new InvalidArgumentException(JText::sprintf('JLIB_APPLICATION_ERROR_INVALID_CONTROLLER_CLASS', $class));
     }
     return self::$instance;
 }
开发者ID:exntu,项目名称:joomla-cms,代码行数:68,代码来源:legacy.php


注:本文中的JControllerLegacy::instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。