API16

JTableNested/getPath: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Method to get an array of nodes from a given node to its root. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JTableNested/getPath...
 
m clean up
Line 2: Line 2:
Method to get an array of nodes from a given node to its root.
Method to get an array of nodes from a given node to its root.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JTableNested/getPath|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JTableNested/getPath}}
 
{{subst:Description:JTableNested/getPath}}


===Syntax===
===Syntax===
Line 63: Line 61:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JTableNested/getPath|Edit See Also]]<nowiki>]</nowiki>
{{subst:SeeAlso:JTableNested/getPath}}
</span>
{{SeeAlso:JTableNested/getPath}}


===Examples===
===Examples===

Revision as of 14:30, 24 March 2017

Description

Method to get an array of nodes from a given node to its root.


{{subst:Description:JTableNested/getPath}}

Syntax

getPath($pk=null, $diagnostic=false)
Parameter Name Default Value Description
$pk null Primary key of the node for which to get the path.
$diagnostic false Only select diagnostic data for the nested sets.

Returns

mixed Boolean false on failure or array of node objects on success.

Defined in

libraries/joomla/database/tablenested.php

Importing

jimport( 'joomla.database.tablenested' );

Source Body

public function getPath($pk = null, $diagnostic = false)
{
        // Initialise variables.
        $k = $this->_tbl_key;
        $pk = (is_null($pk)) ? $this->$k : $pk;

        // Get the path from the node to the root.
        $select = ($diagnostic) ? 'SELECT p.'.$k.', p.parent_id, p.level, p.lft, p.rgt' : 'SELECT p.*';
        $this->_db->setQuery(
                $select .
                ' FROM `'.$this->_tbl.'` AS n, `'.$this->_tbl.'` AS p' .
                ' WHERE n.lft BETWEEN p.lft AND p.rgt' .
                ' AND n.'.$k.' = '.(int) $pk .
                ' ORDER BY p.lft'
        );
        $path = $this->_db->loadObjectList();

        // Check for a database error.
        if ($this->_db->getErrorNum()) {
                $this->setError($this->_db->getErrorMsg());
                return false;
        }

        return $path;
}


{{subst:SeeAlso:JTableNested/getPath}}

Examples

<CodeExamplesForm />