API16:JTableNested/getRootId
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Gets the ID of the root item in the tree
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; }
[Edit See Also] SeeAlso:JTableNested/getRootId
Examples
<CodeExamplesForm />
