0

我一直在尝试学习如何构建 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

现在我虽然要做到这一点,它需要一个 url,其中包括com_joomproSubs?task=submanager

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

4

2 回答 2

3

在 Joomla!一切都通过index.php(尽管在前端,index.php如果 SEF 选项打开,您将不会在 URL 中看到)。

没有 SEF 等

所以入口点是index.php/administrator/index.php(对于后端)。对此附加了一些告诉 Joomla! 的参数。如何路由请求。

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

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

于 2013-04-23T00:05:49.353 回答
1

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

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

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

于 2013-04-23T07:58:18.707 回答