Question

The method JComponentHelper::isEnabled('com_extension', true); checks if an extension is installed and returns a boolean.

The function will also throw an exception notice it the component is not installed due to the self::getComponent($option, $strict); in the same helper class.

Is there a way to avoid the notice if the component is not installed?

Was it helpful?

Solution

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

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

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

OTHER TIPS

While realizing that this is an old question, it is also one of Google's first results and I wanted to share what works for me while avoiding extra database queries.

To avoid the exception you can also check to see if the entry point file of the extension exists like:

if (file_exists(JPATH_ADMINISTRATOR . '/components/com_extension/extension.php') && JComponentHelper::isEnabled('com_extension', true))
    {
        // Your code here
    }

You could use the same function isEnabled and catch that exception, so if the exception is thrown then the component is not installed.

Check out

JComponentHelper::isInstalled('com_extension');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top