1
votes

I can't use a helper function

I've a helper file in site->helpers->document_management.php

I've a class in that file defined('_JEXEC') or die;

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

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

In my site->views->document->view.html.php

I attempt to call the function 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';

I just get

PHP Fatal error: Class 'Document_managmentHelper' not found in /var/www/vhosts/mydomain.com/httpdocs/components/com_document_managment/views/document/view.html.php on line xx

I can't figure it out

1
JView? Also your function isn't declared as static you shouldn't call it as a static. Also you don't say what version you are in but in J+ it would be JViewLegacy. - Elin
@Elin: the helpers class and methods should be static; some Joomla versions allow some slack but it's best to simply declare both as static. user1616338, did it work with require_once? the class is not loaded... - Riccardo Zorn
I really think the lowercase V is the issue. - Elin

1 Answers

0
votes

I called the helper's method in default.php of my custom component's view by following method below:

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