Swift Swift -4 years ago 164
PHP Question

Joomla, how get component id in plugin using component name

I have created plugin in group content. Now i want to fetch component or extension id using component name.

I am using below code

$com_articles = JTable::getInstance( 'component');

But error log showing error

[09-Nov-2016 09:41:01 Etc/GMT] PHP Fatal error: Call to a member function loadByOption() on boolean in /home/phprilpk/public_html/demo/refer/plugins/content/auto_menu/auto_menu.php on line 17

Answer Source

Extensions are stored in prefix_extensions table in database. You can get extension data using jFactory::getDBO();

See this code.

$db = JFactory::getDBO();
$com_articles = $db->setQuery("SELECT * FROM #__extensions WHERE name = 'com_directory'");
$com_articles = $com_articles->loadObject();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download