Best method to check if a component is installed/enabled?



Between joomla 2.5 and 3.x what is the best way to check if another component is installed and/or enabled? There exist a helper class called JComponentHelper but I believe the isEnabled function will actually thrown an error if the component being checked is not installed on some joomla versions.

This can be as simple as hitting up the database directly but I wanted to see if there are other classes/helpers/methods people use.


Posted 2014-04-24T20:08:55.543

Reputation: 682



I use this way:

// Check for component
if (!JComponentHelper::getComponent('<component name>', true)->enabled)

<component name> - without "com_" prefix


Posted 2014-04-24T20:08:55.543

Reputation: 7 152


try this,

Check your database to see if the component is installed and enabled.

$db = JFactory::getDbo();
$db->setQuery("SELECT enabled FROM #__extensions WHERE name = 'com_name'");
$is_enabled = $db->loadResult();

if the value of $is_enabled is 1, then your component is enabled. otherwise,

if (!JComponentHelper::isEnabled('com_mycomp', true))
    JError::raiseError('404', JText('Component not installed / enabled'));


Posted 2014-04-24T20:08:55.543

Reputation: 185


You are right that some versions will display an error if the component does not exist. As far as I know JComponentHelper::getComponent('com_name', true)->enabled is the best check if a component is enabled.

In Joomla 3.0 and above, you can use this even if the component is not installed.

In Joomla 2.5, even the latest release (2.5.19) will throw a JError::raiseWarning message that will be output to the end user if the component is not installed. If you want to support J2.5, it would seem that you would have to use your own helper to load the component. (You could probably make a new helper that extends JComponentHelper and just overrides the _load function to get the same features with just the minor change.)

David Fritsch

Posted 2014-04-24T20:08:55.543

Reputation: 3 700