【问题标题】:How to include helper file from custom template?如何从自定义模板中包含帮助文件?
【发布时间】:2014-03-04 19:25:27
【问题描述】:

请告诉我如何从自定义模板中包含帮助文件?

例如,我想从 /modules/mod_breadcrumbs/helper.php 获取 ModBreadCrumbsHelper 类

在自定义模板/templates/test/html/com_content/article/default.php中

【问题讨论】:

    标签: php class joomla helper


    【解决方案1】:

    添加文件有一种“核心”方式。

    JLoader::register('MyHelperClass', JPATH_ROOT . '/modules/mod_breadcrumbs/helper.php');
    

    【讨论】:

      【解决方案2】:

      您可以使用 include() 或 include_once() 来实现这一点。

      http://us2.php.net/manual/en/function.include.php

      http://us2.php.net/manual/en/function.include-once.php

      示例:(在 /templates/test/html/com_content/article/default.php 内)

      include "/modules/mod_breadcrumbs/helper.php"; // provided the directory "modules" is inside the directory containing "default.php"
      
      $class = new ModBreadCrubmsHelper();
      
      $class->stuff();
      

      【讨论】:

      • 还有没有什么标准的方式,比如JDoc::Include('modue.helper.'); ?
      • @Vladimir - 否。jdoc:include 用于指示 Joomla 其他部分或其扩展的输出应放置在整个网页中的位置。您将在模板 index.php 文件中看到诸如 <jdoc:include type="component" /> 之类的内容,它指示输出组件的位置等。要包含帮助文件,请使用 Jonny 回答中的方法
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多