如何获取组件参数? [英] How to get component parameters?

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

问题描述

我在这里有问题,只是无法解决:-/

I have a problem here and just cant solve it :-/

我正在开发带有后端的Joomla组件. 在后端,我设置了一个参数dashboardId,但无法在视图中访问它们.我总是得到data:protected(当我转储params时).看来我不允许访问该对象.

I am developing an Joomla component with backend. In the backend I set a parameter, the dashboardId, but I can't access them in the view. I always get data:protected (when I dump params). It seems like I'm not allowed to access the object.

这是default.xml:

<?xml version="1.0" encoding="utf-8"?>
<metadata>
    <layout title="Dashboard">
        <message>
            <![CDATA[dashboard LAYOUT DESCRIPTION]]>
        </message>
    </layout>
    <fields name="params">
        <fieldset name="params">
            <field
                name="dashboardId" 
                type="text" 
                label="Dashboard ID"
                description="com_dashboard_desc"
                default="1"
            >   
            </field>
        </fieldset>
    </fields>
</metadata>

现在,在view.html.php中,我尝试像这样访问参数:

Now, in the view.html.php I try to access the parameter like this:

$app = &JFactory::getApplication();
$params = JComponentHelper::getParams('com_dashboard');
$dashboardId = $params->get('dashboardId');
var_dump($dashboardId);

当我执行var_dump($dashboardId);时,我得到NULL,但是当我转储$app时,我可以看到dashboardID

When I do var_dump($dashboardId); I get NULL but when I dump $app, I can see the dashboardID

我们将不胜感激! 谢谢

every help would be appreciated! Thanks

推荐答案

还有一种更简单的方法. 首先导入Joomla组件帮助器:

There's a more simple way. First import Joomla Component Helper:

jimport('joomla.application.component.helper'); // not required in Joomla 3.x

然后像这样检索您想要的任何属性:

And then retrieve any attribute you want like this:

$params = JComponentHelper::getParams('com_dashboard');
$dashboardID = $params->get('dashboardID');

问候.

这篇关于如何获取组件参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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