eZ components PHP Cross Reference Developer Tools

Source: /Tree/docs/tutorial_example_database_one_field.php - 33 lines - 1182 bytes - Summary - Text - Print

   1  <?php
   2  require_once  'tutorial_autoload.php';
   3  
   4  $dbh = ezcDbFactory::create( 'sqlite://:memory:' );
   5  $dbh->exec( <<<ENDSQL
   6      CREATE TABLE nested_set (
   7          'id' varchar(255) NOT NULL,
   8          'parent_id' varchar(255),
   9          'lft' integer NOT NULL,
  10          'rgt' integer NOT NULL
  11      );
  12      CREATE UNIQUE INDEX 'nested_set_pri' on 'nested_set' ( 'id' );
  13      CREATE INDEX 'nested_set_left' on 'nested_set' ( 'lft' );
  14      CREATE INDEX 'nested_set_right' on 'nested_set' ( 'rgt' );
  15  
  16      CREATE TABLE data (
  17          'node_id' varchar(255) NOT NULL,
  18          'data_field' varchar(255) NOT NULL
  19      );
  20      CREATE UNIQUE INDEX 'data_pri' on 'data' ( 'node_id' );
  21  ENDSQL
  22  );
  23  
  24  $store = new ezcTreeDbExternalTableDataStore( $dbh, 'data', 'node_id', 'data_field' );
  25  $tree = new ezcTreeDbNestedSet( $dbh, 'nested_set', $store );
  26  
  27  $tree->setRootNode( $rootNode = $tree->createNode( 'Elements', 'Elements' ) );
  28  $rootNode->addChild( $nonMetal = $tree->createNode( 'NonMetals', 'Non-Metals' ) );
  29  $rootNode->addChild( $nobleGasses = $tree->createNode( 'NobleGasses', 'Noble Gasses' ) );
  30  $nonMetal->addChild( $tree->createNode( 'H',  'Hydrogen' ) );
  31  
  32  echo $tree->fetchNodeById( 'H' )->data, "\n";
  33  ?>

title

Description

title

Description

title

Description

title

title

Body