Joomla 3 - 如何从配置文件中获取价值? [英] Joomla 3 - How to get value from configuration file?

查看:21
本文介绍了Joomla 3 - 如何从配置文件中获取价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个自定义组件,我只想从我的控制器的全局配置中获取一个值.我找不到有关如何执行此操作的任何信息.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆