Joomla 3-如何从配置文件中获取价值? [英] Joomla 3 - How to get value from configuration file?
问题描述
我正在构建一个自定义组件,我只想从控制器的全局配置中获取一个值.我找不到有关如何执行此操作的任何信息.
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.
类似...
$config = JFactory::getConfig();
$this->_db = $config->get('db');
推荐答案
有关操作方法的文档有些过时:
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');
此外,如果您尝试连接到数据库,则实际上只能使用JFactory中的DB对象.
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
这篇关于Joomla 3-如何从配置文件中获取价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!