【问题标题】:Administrator overrides in Joomla 3Joomla 3 中的管理员覆盖
【发布时间】:2014-05-13 20:10:04
【问题描述】:

我正在尝试覆盖

/administrator/components/com_media/views/imageslist 

为了使显示更有用,因为当文件夹中有很多大图像时,列表加载速度很慢。但是,我无法使覆盖工作: 我已经复制了文件

/administrator/components/com_media/views/imageslist/tmpl/default.php and 
/administrator/components/com_media/views/imageslist/tmpl/default_image.php 

/administrator/templates/isis/html/com_media/imageslist

isis 被设置为安装中的默认管理模板。在管理员中(在 iframe 中)显示 com_media 时,使用以下 url:

/administrator/index.php?option=com_media&view=imagesList&tmpl=component&folder=

但它总是使用直接从 com_media 加载的文件,而不是从模板覆盖加载。 (我注意到视图显示为 imagesList,而文件夹名称为 imageslist)。这可能只是 joomla 中的一个错误。有什么想法吗?

问候乔纳斯

编辑:试图深入挖掘。似乎当 JViewLegacy 调用 loadtemplate 时,路径是这样的:

Array ( 
[0] => /home/XXX/www/administrator/components/com_media/views/imageslist/tmpl/ 
[1] => /home/XXX/www/administrator/templates/isis/html/com_media/imageslist/ 
[2] => /home/XXX/www/administrator/components/com_media/views/imageslist/tmpl/ )

所以即使覆盖的路径在路径中,它也不会作为第一个命中,而是加载的是原始组件中的文件而不是覆盖。但是,我仍然不知道为什么会发生这种情况。任何帮助表示赞赏。

【问题讨论】:

    标签: joomla joomla3.0


    【解决方案1】:

    这很有趣,我认为这与使用组件格式而不是 html 格式有关...如果您查看插件,您会看到链接如下所示:

    $link = 'index.php?option=com_media&view=images&tmpl=component&e_name=' . $name . '&asset=' . $asset . '&author=' . $author;

    tmpl=component 意味着它不会使用 index.php,而是会使用 component.php。

    我还没有深入研究代码,但我认为覆盖不会因此而起作用。

    【讨论】:

    • 嗯,我现在尝试调试这个,但并没有真正找到错误。它显然不依赖于 tmpl=component - 位,当我删除它时错误是一样的。
    • 哇,订单问题绝对是关键。这绝对不是标准行为
    【解决方案2】:

    帖子已经 9 个月大了,但我也有同样的奇怪行为……问题出在 com_media 控制器中……具体来说,该组件将模板路径添加到第 68 行的路径列表中……

    https://github.com/joomla/joomla-cms/blob/master/administrator/components/com_media/controller.php#L68

    我删除了核心组件中覆盖工作的行。

    【讨论】:

    【解决方案3】:

    对于 com_media 覆盖,我解决此问题的一种方法是创建一个带有 onAfterRoute() 事件处理程序的系统插件,以捕获和评估请求 URL 参数。然后我可以设置模板覆盖路径并为我的视图和模板使用包含。我在 /plugins/system/mycommedia/mycommedia.php 中的示例系统插件代码,

    // no direct access
    defined ( '_JEXEC' ) or die ( 'Restricted access' );
    
    jimport('joomla.plugin.plugin');
    
    class plgSystemMyComMedia extends JPlugin { 
    
        public function onAfterRoute() {
    
            if('com_media' == JRequest::getCMD('option')) {
    
                $view = JRequest::getCMD('view');
    
                if (('images' == $view) || ('imageslist' == $view)) {
    
                    $overridePath = FOFPlatform::getInstance()->getTemplateOverridePath('com_media', true) . '/' . $view;
    
                    require_once $overridePath . '/view.html.php';
                }
            }
        }
    }
    

    上面的这个版本的 onAfterRoute() 函数展示了如何为后端(管理员)视图和模板应用覆盖。

    public function onAfterRoute() {
    
        $app = JFactory::getApplication();
    
        if ($app->isAdmin()) {
    
            if('com_media' == JRequest::getCMD('option')) {
    
                $view = JRequest::getCMD('view');
    
                if (('images' == $view) || ('imageslist' == $view)) {
    
                    $overridePath = FOFPlatform::getInstance()->getTemplateOverridePath('com_media', true) . '/' . $view;
    
                    require_once $overridePath . '/view.html.php';
                }
            }
        }
    }
    

    通过从 com_media 组件复制到您的模板文件夹来创建新的自定义模板和视图。例如,如果您想为您的管理员 isis 模板自定义媒体管理器:

    复制 /administrator/components/com_media/views/images 到 /administrator/templates/isis/html/com_media/images

    复制 /administrator/components/com_media/views/imageslist 到 /administrator/templates/isis/html/com_media/imageslist

    然后修改 view.html.php 的两个副本以包含它们各自的默认模板副本。

    在显示函数的最后,注释掉或者替换,

    parent::display($tpl);
    

    在模板副本中包含指令,

    include( dirname(__FILE__) . '/tmpl/default.php');
    

    还要注释或替换 imageslist 默认模板中的 loadTemplate('folder') 和 loadTemplate('image') 函数调用,以包含它们各自的文件和文件夹默认模板副本。

    例如,在 /administrator/templates/isis/html/com_media/imageslist/tmpl/default.php 中

    <?php for ($i = 0, $n = count($this->folders); $i < $n; $i++) :
        $this->setFolder($i);
        //echo $this->loadTemplate('folder');
        include( dirname(__FILE__) . '/default_folder.php');
    endfor; ?>
    
    <?php for ($i = 0, $n = count($this->images); $i < $n; $i++) :
        $this->setImage($i);
        //echo $this->loadTemplate('image');
        include( dirname(__FILE__) . '/default_image.php');
    endfor; ?>
    

    com_media 视图和模板现在将被加载而不是它们的核心对应物,并且可以在不破解任何核心 Joomla 文件的情况下进行自定义。

    更多信息@http://jimfrenette.com/joomla/customizing-joomla-media-manager/

    【讨论】:

      猜你喜欢
      • 2014-02-06
      • 2014-12-09
      • 2016-09-04
      • 1970-01-01
      • 2013-06-02
      • 2019-07-09
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      相关资源
      最近更新 更多