LateNight Coding

  • Increase font size
  • Default font size
  • Decrease font size
Home FAQs Developers How can I get the path to Joomla! (or a component) folder?

How can I get the path to Joomla! (or a component) folder?

The path to the folder where Joomla! is installed is stored in a constant defined by the framework

JPATH_SITE

This constant always contains a path on the server's file system. The statement

echo JPATH_SITE;

will output something like

/home/account_name/public_html

This only an example. If you try to echo the constant on your site, the result will likely be different. If you host your Joomla! site with an hosting company the actual path depends by how they organize user accounts on their servers.

But all these details are largely irrelevant. Use JPATH_SITE whenever in your code you need to build a path relative to the folder where Joomla! is installed and you will never be wrong.

While developing a Joomla! component we often need to build a path relative to the folder where the component is installed. We could simply use, for example

$mycom_folder = JPATH_SITE . DS . 'components' . DS . 'com_componentname';

DS means directory separator and is a constant used to build paths that are indipendent from the server's operating system where Joomla! is running. DS is initialized with / in a UNIX/Linux environment and with \ in a MS Windows environment.

But we also have available a handy shortcut

JPATH_COMPONENT_SITE

When used in a file that is part of a component, this constant contains the path to the frontend folder of that particular component.

There is also

JPATH_COMPONENT_ADMINISTRATOR

As it's now easy to guess, we can use this constant in a file that is part of a component to get the path to the backend folder of the component. In other words the constant is equivalent to

JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_componentname'

Here's another one!

JPATH_COMPONENT

This constant is equivalent to JPATH_COMPONENT_SITE or JPATH_COMPONENT_ADMINISTRATOR respectively when used in a file that is part of a component frontend or backend.

 
English Italiano
Support the development of our open source products.

Mootools

GNU GPL License Version 3

120x60c