12

I'm building a custom component and I just want to get a value from the global config in my controller. I can't find any information about how to do this.

Something like...

$config = JFactory::getConfig();
$this->_db = $config->get('db');
BadHorsie
  • 14,135
  • 30
  • 117
  • 191

2 Answers2

18

The documentation on how to do it is slightly outdated:

http://docs.joomla.org/JFactory/getConfig

But if you check the code they actually drop the ampersand function:

https://github.com/joomla/joomla-cms/blob/staging/components/com_users/models/registration.php

$config = JFactory::getConfig();
$fromname = $config->get('fromname');

Also if you are trying to connect to the database you really can just use the DB object from JFactory.

$db = JFactory::getDbo();

Learn more about properly connecting to the database here:

http://docs.joomla.org/Accessing_the_database_using_JDatabase

Chad Windnagle
  • 645
  • 4
  • 7
5

Since Joomla 3.2:

JFactory::getApplication()->get($varname, $default);

See the reference

Dmitrijs Rekuns
  • 523
  • 3
  • 12
  • 1
    Reference is broken, but new link is here: https://docs.joomla.org/Using_the_JFactory_class#JFactory::getConfig.28.29 – user101289 May 03 '17 at 04:58