【问题标题】:Joomla 2.5 component controller loadingJoomla 2.5 组件控制器加载
【发布时间】:2013-04-15 03:06:42
【问题描述】:

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

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

【问题讨论】:

    标签: joomla components


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

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

      没有 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!加载/com_content/controllers/目录中的article.php文件并触发方法edit

      view

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

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

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

      【讨论】:

        猜你喜欢
        • 2013-09-02
        • 2012-12-24
        • 1970-01-01
        • 2013-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-02
        • 1970-01-01
        相关资源
        最近更新 更多