Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] JDom outside component

[FIXED] JDom outside component 13 Mar 2012 14:52 #1589

  • M4d3L
  • M4d3L's Avatar
  • Offline
  • Senior Member
  • Posts: 45
  • Thank you received: 7
  • Karma: 3
I try to use JDom from a module but I have error : JError: Unable to load JDom class : JDomHtml

I include it in my module like :
if (!class_exists('JDom'))
		require_once(JPATH_ADMINISTRATOR. '/components/com_building/dom/dom.php');

do I miss something or?

in an other hand, I think you should think about put JDom into a Library package and not be a part of a component. (In case we have many Component using JCook.
The administrator has disabled public write access.

Re: JDom outside component 26 Mar 2012 21:10 #1730

  • dmd
  • dmd's Avatar
  • Offline
  • New Member
  • Posts: 1
  • Thank you received: 1
  • Karma: 0
M4d3L wrote:
I try to use JDom from a module but I have error : JError: Unable to load JDom class : JDomHtml

I include it in my module like :
if (!class_exists('JDom'))
		require_once(JPATH_ADMINISTRATOR. '/components/com_building/dom/dom.php');

do I miss something or?

in an other hand, I think you should think about put JDom into a Library package and not be a part of a component. (In case we have many Component using JCook.
I second that, as I have just started my first project with j-cook and have straight away run into the problem that when I am developing a module I want to use JDom's html.fly.file to display an image from within the module. When I try to include the JDom using this code:
$slides[$k]['image_url'] = JDom::_('html.fly.file', array(
    'dataKey' => 'image',
    'dataObject' => $slide,
    'width' => 'auto',
    'height' => 'auto',
    'indirect' => true,
    'root' => '[DIR_SLIDES_IMAGE]'
    ));
I get the error:

JError: Unable to load JDom class : JDomHtml

Then when I try to include the class JDomHtml like this:
if (!class_exists('JDom'))
	require_once(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_hicslider'.DS.'dom'.DS.'dom.php');
if (!class_exists('JDomHtml'))
	require_once(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_hicslider'.DS.'dom'.DS.'html.php');
I get the same error:

JError: Unable to load JDom class : JDomHtml

This is because JDom::searchFile() is using constants JPATH_ADMINISTRATOR to build the path to the class file, but since the module is being used on the home page, the value of JPATH_ADMINISTRATOR points to com_content instead of com_hicslider.

I think that centralizing JDom or designing it so it can be used outside of the component is necessary. This could be achieved by using variables instead of constants in JDom::searchFile() or using JPATH_ROOT instead of JPATH_ADMINISTRATOR.

I would like to know if there are any work-arounds that will allow me to use JDom in a module on a page that does not use the j-cook component. For now I will just make my image link directly to the image file, but I would not like to do this for every project, I would rather use JDom like it should be used.

Thank you :)
The administrator has disabled public write access.
The following user(s) said Thank You: Tomaselli

Re: JDom outside component 20 Apr 2012 08:34 #2073

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 985
  • Karma: 140
Sorry for beiing long to answer.


I check this now.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: JDom outside component 20 Apr 2012 10:04 #2079

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 985
  • Karma: 140
There were some errors that should be fixed now.


If you want to load JDom from a module, you are doing well.

You should notice that JDom can accept overrides of classes inside the same joomla instance.
So, if you want to open a specific classes tree, you can precise the extension in params :

JDom::_('html.fly.file', array(
    'dataKey' => 'image',
    'dataObject' => $slide,
    'width' => 'auto',
    'height' => 'auto',
    'indirect' => true,
    'root' => '[DIR_SLIDES_IMAGE]'


    'extension' => 'com_xxxx'		//HERE
    ));

By this way, you choose wich files to use, but this is optional for really specific uses.

It should works now.

EDIT : Regenerate your project.
The only affected file is : dom/dom.php
Coding is now a piece of cake
Last Edit: 20 Apr 2012 10:05 by admin.
The administrator has disabled public write access.
The following user(s) said Thank You: edwardcox
Time to create page: 0.084 seconds

Get Started