Adding new entries is performed in two ways. First, you need to establish a fresh Net_LDAP2_Entry object. After that, you can add that entry like you would add already-existent entries using Net_LDAP2's add() method.
Adding a fresh entry
<?php
// Build a new fresh entry:
$dn = 'cn=new-admin,o=example,dc=org';
$attributes = array(
'cn' => 'new-admin',
'mail' => array('new-admin@exaple.org', 'n.admin@example.de'),
'telephoneNumber' => '1234567890'
);
$entry = Net_LDAP2_Entry::createFresh($dn, $attributes);
// Add the entry to the directory:
$ldap->add($entry);
?>
Renaming and/or moving an entry is an operation on the DN of an entry. Moving an entry means, to rename a DN in such a way, that the entry becomes a new base-DN. You can rename or move an entry, if you call the dn() method of the entry you want to relocate. Alternatively, you may call Net_LDAP2's move() method that also ca handle only DNs. Remember that you must call the entires update() method to carry out the move/rename. Net_LDAP2's move() will move the entry immediately. If you use an entryobject togehter with Net_LDAP2's move(), you are able to perform cross directory moves.
Moving an entry using Net_LDAP2_Entry
<?php
// Defining the DN we want to fetch;
$dn = 'cn=admin,o=example,dc=org';
$newdn = 'cn=admin,o=new-example,dc=org';
$entry = $ldap->getEntry($dn);
$entry->dn($newdn);
?>
Moving an entry using Net_LDAP2 and Net_LDAP2_Entry
<?php
// Defining the DN we want to fetch;
$dn = 'cn=admin,o=example,dc=org';
$newdn = 'cn=admin,o=new-example,dc=org';
$entry = $ldap->getEntry($dn);
$ldap->move($entry, $newdn);
?>
Renaming an entry using Net_LDAP2 and DNs
<?php
// Defining the DN we want to fetch;
$dn = 'cn=admin,o=example,dc=org';
$newdn = 'cn=admin2,o=new-example,dc=org';
$ldap->move($dn, $newdn);
?>
Performing a cross directory move
<?php
// $ldap_src is the source ldap and $ldap_tgt the target
$dn = 'cn=admin,o=example,dc=org';
$newdn = 'cn=admin,o=new-example,dc=org';
$entry = $ldap_src->getEntry($dn);
$ldap_src->move($entry, $newdn, $ldap_tgt);
?>
Deleting entries is performed using Net_LDAP2's delete() method.
Just pass the Net_LDAP2_Entry object or the DN of the entry you want to delete.
In the case that the DN contains subentrys, you need to pass TRUE
as second parameter
which will make delete() delete recursive.
A second way exist: You may simply call delete() from the Net_LDAP2_Entry you want to delete. Don't forget that you must call update() to carry out the delete in this case.
Deleting an entry
<?php
$dn = 'cn=new-admin,o=example,dc=org';
$ldap->delete($dn);
?>
Deleting an entry using a Net_LDAP2_Entry object
<?php
$entry->delete();
$entry->update();
?>