乔姆拉! 2.5:将值设置为受保护的变量

Joomla! 2.5: set value into protected variable

我正在尝试在 JRegistry 对象中(在 $_SESSION 变量中)为受保护对象 'data' 设置一个新变量:

["registry"]=> object(JRegistry)#22 (1) { 

    ["data":protected]=> object(stdClass)#23 (3) {

        ["users"]=> object(stdClass)#24 (1) { 
            …
        } 
        // here is my new variable supposed to be
    }
}

我尝试使用

JRegistry::set($_SESSION['__default']['registry']->data, $test);

JRegistry::setValue($_SESSION['__default']['registry']->data, $test);

但两种方式都会引发错误消息 "Cannot access protected property JRegistry::$data"。 有没有办法写入这个受保护的变量?

你使用的JRegistry调用不正确,你没有传入全局变量$_SESSION。

set()setValue() 调用的签名是:

public function set($path, $value)

public function setValue($path, $value)

N.B. 请注意 setValue() 已弃用。

获得 JRegistry 对象后,您可以通过传递 $path 属性(例如注册表路径,例如 'joomla.content.showauthor')和值。