cvs: peardoc /en/package/database/db-nestedset intro.xml

[email protected] ("Daniel Khan")
Newsgroups php.pear.doc
Message-ID <cvsdatenpunk1190719233@cvsserver>
datenpunk		Tue Sep 25 11:20:33 2007 UTC

  Added files:                 
    /peardoc/en/package/database/db-nestedset	intro.xml 
  Log:
  commit
  

http://cvs.php.net/viewvc.cgi/peardoc/en/package/database/db-nestedset/intro.xml?view=markup&rev=1.1
Index: peardoc/en/package/database/db-nestedset/intro.xml
+++ peardoc/en/package/database/db-nestedset/intro.xml
<!-- $Revision: 1.1 $ -->
<refentry id="package.DB_NestedSet">
 <refnamediv>
  <refname>Introduction</refname>
  <refpurpose>
   Introduction to <classname>DB_NestedSet</classname>
  </refpurpose>
 </refnamediv>

 <refsect1 id="package.DB_NestedSet.intro.overview">
  <title>Overview</title>

  <para>
   With this package, one can easily create trees with infinite depth
   inside a relational database. The package provides a way to
  </para>
  <para>

   <itemizedlist>
    <listitem>
     <simpara>
      create/update/delete nodes
     </simpara>
    </listitem>
    <listitem>
     <simpara>
      query nodes, trees and subtrees
     </simpara>
    </listitem>
    <listitem>
     <simpara>
      copy (clone) nodes, trees and subtrees
     </simpara>
    </listitem>
    <listitem>
     <simpara>
      move nodes, trees and subtrees
     </simpara>
    </listitem>
    <listitem>
     <simpara>
      etc.
     </simpara>
    </listitem>
   </itemizedlist>
</para>
 </refsect1>

 <refsect1 id="package.DB_NestedSet.intro.examples">
  <title>An example</title>

  <example>
   <title>
    Creates some root and subnodes
   </title>
   <para>
    In this example, one rootnode and two subnodes are created,
    saved to the database and displayed.
   </para>
   <programlisting role="php">
require_once('DB/NestedSet.php');
require_once('DB/NestedSet/Output.php');
$DatabasePointer = mysql_connect("localhost", "user", "pwd");
mysql_select_db("database", $DatabasePointer);
$dsn = 'mysql://database:pwd@localhost/user';
// needed colums in table:
$params = array(
	'id'        => 'id',
	'parent_id' => 'rootid',
	'left_id'   => 'l',
	'right_id'  => 'r',
	'order_num' => 'norder',
	'level'     => 'level',
	'name'      => 'name',
);
$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
$nestedSet->setAttr(array(
		'node_table' => 'nested_set',
		'lock_table' => 'nested_set_locks',
		'secondarySort' => 'name',
	)
);
$parent = $nestedSet->createRootNode(array('name' =>'root 1'), false, true);
$nestedSet->createSubNode($parent, array('name' => 'node 1.1'));
$nestedSet->createSubNode($parent, array('name' =>'node 1.2'));
$data = $nestedSet->getAllNodes(true);

foreach ($data as $id => $node) {
     $data[$id]['url'] = $_SERVER['PHP_SELF'].'?nodeID=' . $node['id'];
}

$params = array(
    'structure' => $data,
    'titleField' => 'name',
    'urlField' => 'url');
$output =& DB_NestedSet_Output::factory($params, 'Menu');
$menu = & new HTML_Menu($structure, 'sitemap');
$menu->forceCurrentUrl($currentUrl);
$menu->show();
   </programlisting>
  </example>

 </refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.