11

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.

11

I use this way:

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

<component name> - without "com_" prefix

4

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'));
}
3

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.)

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.