Joomla 3 - How to get value from configuration file?
Asked Answered
W

2

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');
Woodhead answered 11/2, 2014 at 13:18 Comment(0)
T
19

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

Tabard answered 11/2, 2014 at 13:56 Comment(0)
P
5

Since Joomla 3.2:

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

See the reference

Policeman answered 11/2, 2014 at 13:59 Comment(1)
Reference is broken, but new link is here: docs.joomla.org/…Tickle

© 2022 - 2024 — McMap. All rights reserved.