【问题标题】:Joomla calling a Helper from within view.html.phpJoomla 从 view.html.php 中调用 Helper
【发布时间】:2013-09-26 22:21:36
【问题描述】:

我不能使用辅助函数

我在 site->helpers->document_management.php 中有一个帮助文件

我在那个文件中有一个类 定义('_JEXEC')或死;

            /**
            * Document_managment helper.
            */
            class Document_managmentHelper
            {

            function testFunction()
            {
                $textis= "hello";
                return $textis; 
            }
            }

在我的站点->views->document->view.html.php

我尝试调用函数testFunction:

            $callingCard = Jview::loadHelper('Document_managment');
            //require_once JPATH_COMPONENT.'/helpers/document_managment.php';
            $getprofileinfo = Document_managmentHelper::testFunction();
            echo getprofileinfo;    
            echo "test is ". JPATH_COMPONENT.'/helpers/document_managment.php';

我才明白

PHP 致命错误:在第 xx 行的 /var/www/vhosts/mydomain.com/httpdocs/components/com_document_managment/views/document/view.html.php 中找不到类“Document_managmentHelper”

我想不通

【问题讨论】:

  • JView?此外,您的函数未声明为静态,您不应将其称为静态。你也没有说你在哪个版本,但在 J+ 中它会是 JViewLegacy。
  • @Elin:助手类的方法应该是静态的;一些 Joomla 版本允许一些松弛,但最好简单地将两者声明为静态。 user1616338,它与require_once一起工作吗?该类未加载...
  • 我真的认为小写 V 是问题所在。

标签: joomla components


【解决方案1】:

我通过以下方法在我的自定义组件视图的 default.php 中调用了 helper 方法:

$isEnable = CustomFrontendHelper::getTheMethod('is_enable'); // a static function in the helper

【讨论】:

  • 如果解释得更详细一点,这可能真的很有帮助 - getTheMethod 是您创建的方法的名称,还是方法名称是 is_enable?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多