API16:JRegistry/setValue
From Joomla! Documentation
Description
Set a registry value
Syntax
setValue($regpath, $value)
| Parameter Name | Default Value | Description |
|---|---|---|
| $regpath | Registry Path (e.g. joomla.content.showauthor) | |
| $value | Value of entry |
Returns
mixed The value after to setting.
Defined in
libraries/joomla/registry/registry.php
Importing
jimport( 'joomla.registry.registry' );
Source Body
public function setValue($regpath, $value)
{
// Explode the registry path into an array
$nodes = explode('.', $regpath);
// Get the namespace
$count = count($nodes);
if ($count < 2) {
$namespace = $this->_defaultNameSpace;
} else {
$namespace = array_shift($nodes);
$count--;
}
if (!isset($this->_registry[$namespace])) {
$this->makeNameSpace($namespace);
}
$ns = & $this->_registry[$namespace]['data'];
$pathNodes = $count - 1;
if ($pathNodes < 0) {
$pathNodes = 0;
}
for ($i = 0; $i < $pathNodes; $i ++) {
// If any node along the registry path does not exist, create it
if (!isset($ns->$nodes[$i])) {
$ns->$nodes[$i] = new stdClass();
}
$ns = &$ns->$nodes[$i];
}
// Set the new value.
$ns->$nodes[$i] =& $value;
return $ns->$nodes[$i];
}
Examples
Code Examples