2

我有两个引用外部数据库的自定义组件。在 component1 中,我设置了连接到该外部数据库所需的参数。

有没有办法可以在component2中使用component1中的参数集?

我在组件2中的模型中的代码:

$app = JFactory::getApplication();
$params = $app->getParams('com_component1');

告诉我一个致命错误:

Fatal error: Call to undefined method JApplicationAdministrator::getParams() in /var/www....

我应该停止偷懒并在component2中重新定义相同的参数,还是有合理的解决方案?

4

1 回答 1

3

Try using the following code.

$params = JComponentHelper::getParams('com_component1');
$test = $params->get('param_name');

To get parameters, you need to use JComponentHelper, not JFactory.

于 2014-01-28T19:30:53.500 回答