Joomla 2.5组件控制器加载

时间:2013-04-22 09:09:41

标签: joomla components

我一直在努力学习如何构建Joomla组件。

我一直在使用http://joomlaprogrammingbook.com/这本书很棒。我现在可以做插件和模块而不会有太多问题。但是我对某些控制器如何为组件加载感到困惑。如果需要,给出的网站有完整的代码。

加载的初始控制器是:

 class JoomproSubsController extends JController
{
    /**
    * @var      string  The default view.
    * @since    1.6
    */
protected $default_view = 'submanager';

/**
 * Method to display a view.
 *
 * @param   boolean         $cachable   If true, the view output will be cached
 * @param   array           $urlparams  An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
 *
 * @return  JController     This object to support chaining.
 */ 
public function display($cachable = false, $urlparams = false)
{
    JLoader::register('JoomproSubsHelper', JPATH_COMPONENT.'/helpers/joomprosubs.php');

    // Load the submenu.
    JoomproSubsHelper::addSubmenu(JRequest::getCmd('view', 'submanager'));

    $view = JRequest::getCmd('view', 'submanager');
    $layout = JRequest::getCmd('layout', 'default');
    $id = JRequest::getInt('id');

    // Check for edit form.
    if ($view == 'subscription' && $layout == 'edit' && !$this->checkEditId('com_joomprosubs.edit.subscription', $id)) {
        // Somehow the person just went to the form - we don't allow that.
        $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
        $this->setMessage($this->getError(), 'error');
        $this->setRedirect(JRoute::_('index.php?option=com_joomprosubs&view=submanager', false));

        return false;
    }

    parent::display();

    return $this;
}

}

我可以看到它是如何以及何时加载的。但是在某些方面它似乎也加载了class JoomproSubsControllerSubManager extends JControllerAdmin

现在我要做到这一点,它需要一个包含com_joomproSubs?task=submanager

的网址

但这不存在。所以我的问题是这怎么可能发生?

2 个答案:

答案 0 :(得分:3)

在Joomla!所有内容都会通过index.php(尽管在前端,如果启用了SEF选项,您将无法在网址中看到index.php。)

没有SEF等

因此,入口点为index.php/administrator/index.php(后端)。为此添加了一些告诉Joomla的参数!如何路由请求。

  1. option=X
  2. task=Y.Z
  3. view=V
  4. option

    这是告诉Joomla处理请求的组件的参数。例如option=com_content用于处理标准文章的组件。在确定组件值之后,Joomla希望所有内容都在匹配目录中。在我们的示例中,这将是/components/com_content/或后端/administrator/components/com_content/

    task

    task参数可以采用controller.method形式的点表示法值,例如文章管理器中的task=article.edit。使用这个值的元素Joomla!加载article.php目录中的/com_content/controllers/文件并触发方法edit

    view

    view参数用于指定同一控制器内的特定视图,例如再次在com_content组件中,您会看到视图值中的这两个变体:

    /administrator/index.php?option=com_content&view=featured

    /administrator/index.php?option=com_content&view=articles

答案 1 :(得分:1)

子控制器用于组件项目的新任务,编辑,删除,保存等任务,因为可能有不同类型的这些(横幅/客户端/轨道)具有不同的功能(项目,列表,表单)。

使用网址  com_joomprosubs?task=item.display在文件components / com_joomprosubs / controllers / item.php中执行控制器方法JoomprosubsControlerItem->display()

如果你使用 com_joomprosubs?task=submanager你会在components / com_joomprosubs / controller.php中JoomprosubsController->submanager()