2017 © Pedro Peláez
 

lithium-library li3_tree

Model tree behavior for the Lithium PHP framework

image

jails/li3_tree

Model tree behavior for the Lithium PHP framework

  • Friday, July 5, 2013
  • by jails
  • Repository
  • 3 Watchers
  • 5 Stars
  • 531 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Tree behavior

Requirements

Installation

Checkout the code to either of your library directories:, (*1)

cd libraries
git clone git@github.com:jails/li3_tree

Include the library in your /app/config/bootstrap/libraries.php, (*2)

Libraries::add('li3_tree');

Presentation

This behavior store hierarchical datas in a database table using the MPTT logic., (*3)

Constraints

To use the tree behavior, your table needs the following 3 extra fields:, (*4)

  • The 'parent' config field. By default the field must be named parent_id in the table.
  • The 'left' config field. By default the field must be named lft in the table.
  • The 'right' config field. By default the field must be named rght in the table.

API

Example of attaching the tree behavior to a model:, (*5)

 ['scope' => ['post_id']]];
}
?>

Options

In order to store multiple trees in the same table you need to set the 'scope' option. For example, if a Post hasMany Comment and a Comment belongsTo a Post. To allow multiple Comment trees in the same table, you must scope Comment by the foreign key post_id. This way all Comment trees will be independant., (*6)

'scope' can be a full condition:, (*7)

 protected $_actsAs = ['Tree' => ['scope' => ['region' => 'head']]];

Or a simple fieldname like a foreign key:, (*8)

 protected $_actsAs = ['Tree' => ['scope' => ['post_id']]];

In this last case, the full condition will be populated from entity datas. This mean you can't do any CRUD action if the entity datas don't contain all necessary datas for perfoming a well scoped CRUD action., (*9)

Example of use:

 1]);
$root1->save();

$root2 = Comment::create(['post_id' => 2]);
$root2->save();

$neighbor1 = Comment::create(['post_id' => 1]);
$neighbor1->save();

$neighbor1->moveDown();
$root1->moveUp();
$neighbor1->move(0);

$subelement1 = Comment::create(['post_id' => 1, 'parent_id' => $neighbor1->id]);
$subelement1->save();

var_export($root1->childrens());
var_export($subelement1->path());
?>

Greetings

The li3 team, Vogan and all others which make that possible (I mean only because Chuck Norris agreed)., (*10)

Build status

Build Status, (*11)

The Versions

05/07 2013

dev-php-5.3

dev-php-5.3 https://github.com/jails/li3_tree

Model tree behavior for the Lithium PHP framework

  Sources   Download

BSD-3-Clause

The Requires

 

php model behavior tree lithium li3

22/06 2013

dev-master

9999999-dev https://github.com/jails/li3_tree

Model tree behavior for the Lithium PHP framework

  Sources   Download

BSD-3-Clause

The Requires

 

php model behavior tree lithium li3