JRegistry/getValue: Difference between revisions
From Joomla! Documentation
m removing red link to edit, no existant pages |
m preparing for archive only |
||
| Line 77: | Line 77: | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=getValue | category=getValue | ||
category=JRegistry | category=JRegistry | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
Latest revision as of 01:03, 25 March 2017
Description
Get a registry value
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
getValue($regpath, $default=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $regpath | $regpath Registry path (e.g. joomla.content.showauthor) | |
| $default | null | $default Optional default value |
Returns
mixed Value of entry or null
Defined in
libraries/joomla/registry/registry.php
Importing
jimport( 'joomla.registry.registry' );
Source Body
function getValue($regpath, $default=null)
{
$result = $default;
// Explode the registry path into an array
if ($nodes = explode('.', $regpath))
{
// Get the namespace
//$namespace = array_shift($nodes);
$count = count($nodes);
if ($count < 2) {
$namespace = $this->_defaultNameSpace;
$nodes[1] = $nodes[0];
} else {
$namespace = $nodes[0];
}
if (isset($this->_registry[$namespace])) {
$ns = & $this->_registry[$namespace]['data'];
$pathNodes = $count - 1;
//for ($i = 0; $i < $pathNodes; $i ++) {
for ($i = 1; $i < $pathNodes; $i ++) {
if((isset($ns->$nodes[$i]))) $ns =& $ns->$nodes[$i];
}
if(isset($ns->$nodes[$i])) {
$result = $ns->$nodes[$i];
}
}
}
return $result;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples