JTableNested/getRootId: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Gets the ID of the root item in the tree
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<n... |
m clean up |
||
| Line 2: | Line 2: | ||
Gets the ID of the root item in the tree | Gets the ID of the root item in the tree | ||
{{Description:JTableNested/getRootId}} | |||
{{subst:Description:JTableNested/getRootId}} | |||
===Syntax=== | ===Syntax=== | ||
| Line 85: | Line 83: | ||
</source> | </source> | ||
{{subst:SeeAlso:JTableNested/getRootId}} | |||
{{SeeAlso:JTableNested/getRootId}} | |||
===Examples=== | ===Examples=== | ||
Revision as of 14:30, 24 March 2017
Description
Gets the ID of the root item in the tree
{{subst:Description:JTableNested/getRootId}}
Syntax
getRootId()
Returns
mixed The ID of the root row, or false and the internal error is set.
Defined in
libraries/joomla/database/tablenested.php
Importing
jimport( 'joomla.database.tablenested' );
Source Body
public function getRootId()
{
// Get the root item.
$k = $this->_tbl_key;
try {
// Test for a unique record with parent_id = 0
$this->_db->setQuery(
'SELECT '.$this->_db->nameQuote($k).
' FROM '.$this->_tbl .
' WHERE `parent_id` = 0'
);
$result = $this->_db->loadResultArray();
if ($this->_db->getErrorNum()) {
throw new Exception($this->_db->getErrorMsg());
}
if (count($result) == 1) {
$parentId = $result[0];
} else {
// Test for a unique record with lft = 0
$this->_db->setQuery(
'SELECT '.$this->_db->nameQuote($k).
' FROM '.$this->_tbl .
' WHERE `lft` = 0'
);
$result = $this->_db->loadResultArray();
if ($this->_db->getErrorNum()) {
throw new Exception($this->_db->getErrorMsg());
}
if (count($result) == 1) {
$parentId = $result[0];
} else if (property_exists($this, 'alias')) {
// Test for a unique record with lft = 0
$this->_db->setQuery(
'SELECT '.$this->_db->nameQuote($k).
' FROM '.$this->_tbl .
' WHERE `alias` = '.$this->_db->quote('root')
);
$result = $this->_db->loadResultArray();
if ($this->_db->getErrorNum()) {
throw new Exception($this->_db->getErrorMsg());
}
if (count($result) == 1) {
$parentId = $result[0];
} else {
throw new Exception(JText::_('JTable_Error_Root_node_not_found'));
}
} else {
throw new Exception(JText::_('JTable_Error_Root_node_not_found'));
}
}
} catch (Exception $e) {
$this->setError($e->getMessage());
return false;
}
return $parentId;
}
{{subst:SeeAlso:JTableNested/getRootId}}
Examples
<CodeExamplesForm />