Development

HowToHandleHierarchicalDataWithPropel (diff)

You must first sign up to be able to contribute.

Changes between Version 5 and Version 6 of HowToHandleHierarchicalDataWithPropel

Show
Ignore:
Author:
Grégory Becker (IP: 82.239.76.51)
Timestamp:
07/24/06 18:44:40 (11 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HowToHandleHierarchicalDataWithPropel

    v5 v6  
    1 This code may be moved to a pear package later. Let's just be sure there aren't bugs in it anymore first. 
     1'''WARNING'''[[BR]] 
     2This code may be moved to a pear package later. Let's just be sure there aren't bugs in it anymore first.[[BR]] 
     3The following source code is NOT ready for production usages. Use it at your own risk.[[BR]] 
     4Method names may change in the future and won't after the first stable release (I hope so).[[BR]] 
    25 
    36= sfPropelTree plugin = 
    110113}}} 
    111114 
    112 Tree structure of each example 
    113 {{{ 
    114   root page 
    115     page 1 
    116     page 2 
    117     page 3 
    118     page 5 
    119     page 8 
    120 }}} 
     115Tree structure for each example 
     116{{{ 
     117  root page 
     118    page 1 
     119    page 2 
     120    page 3 
     121    page 5 
     122    page 8 
     123}}} 
     124 
     125 
    121126 
    122127== add a root node == 
    144149{{{ 
    145150$c = new Criteria(); 
    146 $c->add(PagePeer::TITLE, 'First page'); 
     151$c->add(PagePeer::TITLE, 'page 1'); 
    147152$parent = PagePeer::doSelectOne($c); 
    148153 
    149154$child = new Page(); 
    150155$child->setTitle('Page 1.1'); 
    151 $parent->addChild($child); 
     156$parent->addChild($child); // saves $child in database. No need to call $child->save() after 
     157// addChild is an equivalent to addChildBottom 
     158// you could have typed : 
     159// $parent->addChildBottom($child) 
    152160}}} 
    153161 
    164172}}} 
    165173 
    166 == add a node after another == 
     174== add a child before the other ones == 
     175 
     176We're using the result of the previous example for this one. 
     177 
     178{{{ 
     179$c = new Criteria(); 
     180$c->add(PagePeer::TITLE, 'page 1'); 
     181$parent = PagePeer::doSelectOne($c); 
     182 
     183$child = new Page(); 
     184$child->setTitle('Page 1.0'); 
     185$parent->addChildTop($child); // saves $child in database. No need to call $child->save() after 
     186}}} 
     187 
     188results: 
     189 
     190{{{ 
     191  root page 
     192    page 1 
     193        page 1.0 < 
     194        page 1.1 
     195    page 2 
     196    page 3 
     197    page 5 
     198    page 8 
     199}}} 
     200 
     201== add a node after another one == 
    167202 
    168203{{{ 
    175210 
    176211if ($parent && $child) 
    177   $parent->addAfter($child); 
     212  $parent->addAfter($child); // saves $child in database. No need to call $child->save() after 
    178213}}} 
    179214