Loading Helper file in Joomla

798 views
Skip to first unread message

JCarlos

unread,
Jan 9, 2014, 12:23:05 PM1/9/14
to joomla-de...@googlegroups.com
Hi:
I have tried to import a file "helper" with JHtml::addIncludePath(JPATH_COMPONENT.'/helpers'); but throws me an error saying that the class is not found.

JHtml::addIncludePath(JPATH_COMPONENT.'/helpers');
vgalleryHelperRoute::getGalleryRoute();

outputClass 'vgalleryHelperRoute' not found in ......

However, if I do this, everything works properly:

if(!defined('DS')){
    define('DS',DIRECTORY_SEPARATOR);
}
require_once (JPATH_COMPONENT.DS.'helpers'.DS.'route.php');

vgalleryHelperRoute::getGalleryRoute();

What am I doing wrong with "JHtml::addIncludePath()"?

Michael Babker

unread,
Jan 9, 2014, 12:40:01 PM1/9/14
to joomla-de...@googlegroups.com
JHtml::addIncludePath() adds a path to the lookup array that JHtml uses to find classes when you call JHtml::_('class.action'); so it won't work as a general file loader.


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/groups/opt_out.

Viper

unread,
Jan 9, 2014, 12:47:25 PM1/9/14
to joomla-de...@googlegroups.com
JLoader::register('ClassName', JPATH_COMPONENT.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'classname.php');
// If you use dynamic class
$helper = ClassName::getInstance();

// Or as static
$helper = new ClassName();

JCarlos

unread,
Jan 9, 2014, 1:52:04 PM1/9/14
to joomla-de...@googlegroups.com
Thanks @Michael  apparently I misunderstood the use of JHtml::addIncludePath(). I have a pending read :)

@Viper JLoader::register It worked perfectly, thanks

Dmitry Rekun

unread,
Jan 10, 2014, 2:43:52 AM1/10/14
to joomla-de...@googlegroups.com
Just a note - if you will use more helpers you can discover them using JLoader::discover() method. Read more here.

Dmitry

JCarlos

unread,
Jan 10, 2014, 9:05:40 AM1/10/14
to joomla-de...@googlegroups.com
Thanks @Dmitry

ritr...@gmail.com

unread,
Jan 12, 2014, 6:44:00 PM1/12/14
to joomla-de...@googlegroups.com
Yy
Enviado desde mi BlackBerry de Movistar

From: JCarlos <crsanc...@gmail.com>
Date: Thu, 9 Jan 2014 10:52:04 -0800 (PST)
Subject: [jgen] Re: Loading Helper file in Joomla

Thanks @Michael  apparently I misunderstood the use of JHtml::addIncludePath(). I have a pending read :)

@Viper JLoader::register It worked perfectly, thanks

--
Reply all
Reply to author
Forward
0 new messages