Database Reference
In-Depth Information
Adding a Label to Nodes
In Neo4jPHP, you can add one more labels to a node. As Listing 8-10 shows, the addLabels function takes one or more
labels as argument. You can return each of the labels on a node by calling its getLabels function. The value used for the
label should be any nonempty string or numeric value.
Caution
A label will not exist on the database server until it has been added to at least one node.
Listing 8-10. Creating a Label and Adding It to a Node
<?php
// Neo4jClient class
// ...omitted...
// Create Neo4j client
// ...omitted...
// retrieve the node by its node id value, in this case 10
$greg = $neo4jClient->getNode(10);
// create three labels
$userLabel = $client->makeLabel('User');
$devLabel = $client->makeLabel('Developer');
$memeLabel = $client->makeLabel('GoodGuyGreg');
// add the labels to $greg
$labels = $greg->addLabels(array($userLabel, $devLabel, $memeLabel));
// get the labels for $greg
$labels = $greg->getLabels();
Removing a Label
Removing a label uses similar syntax as adding a label to a node. After the given label has been removed from the
node (Listing 8-12), the return value is a list of labels still on the node.
Listing 8-12. Removing a Label from a Node
<?php
// Neo4jClient class
// ...omitted...
// Create Neo4j client
// ...omitted...
// retrieve the node by its node id value, in this case 10
$greg = $neo4jClient->getNode(10);
// delete the relationship
$remainingLabels = $node->removeLabels(array($memeLabel));
 
 
Search WWH ::




Custom Search