Object relational mapping - Hierarchical data - Introduction - Tree interface.php 924 Bytes
Newer Older
hansbrix's avatar
hansbrix committed
1 2


3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
The tree interface, for creating and accessing the tree, is accessed on a table level. A full implementation of this interface would be as follows:



<code type="php">

interface Doctrine_Tree_Interface {

    /**
     * creates root node from given record or from a new record
     */
    public function createRoot(Doctrine_Record $record = null);

    /**
     * returns root node
     */
    public function findRoot($root_id = 1);

    /**
     * optimised method to returns iterator for traversal of the entire tree from root
     */
    public function fetchTree($options = array());

    /**
     * optimised method that returns iterator for traversal of the tree from the given record's primary key
     */
    public function fetchBranch($pk, $options = array());
}

// if your model acts as tree you can retrieve the associated tree object as follows
$treeObj = $manager->getTable('Model')->getTree();

</code>