Joomla 3 - How to get value from configuration file?

强颜欢笑 提交于 2021-02-07 11:44:06

问题


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

回答1:


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




回答2:


Since Joomla 3.2:

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

See the reference



来源:https://stackoverflow.com/questions/21702981/joomla-3-how-to-get-value-from-configuration-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!