1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.ldap.usage">
4 <title>Usage Scenarios</title>
6 <sect2 id="zend.ldap.usage.authentication">
7 <title>Authentication scenarios</title>
9 <sect3 id="zend.ldap.usage.authentication.openldap">
10 <title>OpenLDAP</title>
14 <sect3 id="zend.ldap.usage.authentication.activedirectory">
15 <title>ActiveDirectory</title>
20 <sect2 id="zend.ldap.usage.basic">
21 <title>Basic CRUD operations</title>
23 <sect3 id="zend.ldap.usage.basic.retrieve">
24 <title>Retrieving data from the LDAP</title>
26 <example id="zend.ldap.usage.basic.retrieve.dn">
27 <title>Getting an entry by its DN</title>
29 <programlisting language="php"><![CDATA[
30 $options = array(/* ... */);
31 $ldap = new Zend_Ldap($options);
33 $hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
35 $hm is an array of the following structure
37 'dn' => 'cn=Hugo Müller,ou=People,dc=my,dc=local',
38 'cn' => array('Hugo Müller'),
39 'sn' => array('Müller'),
40 'objectclass' => array('inetOrgPerson', 'top'),
47 <example id="zend.ldap.usage.basic.retrieve.exists">
48 <title>Check for the existence of a given DN</title>
50 <programlisting language="php"><![CDATA[
51 $options = array(/* ... */);
52 $ldap = new Zend_Ldap($options);
54 $isThere = $ldap->exists('cn=Hugo Müller,ou=People,dc=my,dc=local');
58 <example id="zend.ldap.usage.basic.retrieve.counting-children">
59 <title>Count children of a given DN</title>
61 <programlisting language="php"><![CDATA[
62 $options = array(/* ... */);
63 $ldap = new Zend_Ldap($options);
65 $childrenCount = $ldap->countChildren(
66 'cn=Hugo Müller,ou=People,dc=my,dc=local');
70 <example id="zend.ldap.usage.basic.retrieve.search">
71 <title>Searching the LDAP tree</title>
73 <programlisting language="php"><![CDATA[
74 $options = array(/* ... */);
75 $ldap = new Zend_Ldap($options);
77 $result = $ldap->search('(objectclass=*)',
78 'ou=People,dc=my,dc=local',
79 Zend_Ldap_Ext::SEARCH_SCOPE_ONE);
80 foreach ($result as $item) {
81 echo $item["dn"] . ': ' . $item['cn'][0] . PHP_EOL;
87 <sect3 id="zend.ldap.usage.basic.add">
88 <title>Adding data to the LDAP</title>
91 <title>Add a new entry to the LDAP</title>
93 <programlisting language="php"><![CDATA[
94 $options = array(/* ... */);
95 $ldap = new Zend_Ldap($options);
98 Zend_Ldap_Attribute::setAttribute($entry, 'cn', 'Hans Meier');
99 Zend_Ldap_Attribute::setAttribute($entry, 'sn', 'Meier');
100 Zend_Ldap_Attribute::setAttribute($entry, 'objectClass', 'inetOrgPerson');
101 $ldap->add('cn=Hans Meier,ou=People,dc=my,dc=local', $entry);
106 <sect3 id="zend.ldap.usage.basic.delete">
107 <title>Deleting from the LDAP</title>
110 <title>Delete an existing entry from the LDAP</title>
112 <programlisting language="php"><![CDATA[
113 $options = array(/* ... */);
114 $ldap = new Zend_Ldap($options);
116 $ldap->delete('cn=Hans Meier,ou=People,dc=my,dc=local');
121 <sect3 id="zend.ldap.usage.basic.update">
122 <title>Updating the LDAP</title>
125 <title>Update an existing entry on the LDAP</title>
127 <programlisting language="php"><![CDATA[
128 $options = array(/* ... */);
129 $ldap = new Zend_Ldap($options);
131 $hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
132 Zend_Ldap_Attribute::setAttribute($hm, 'mail', 'mueller@my.local');
133 Zend_Ldap_Attribute::setPassword($hm,
135 Zend_Ldap_Attribute::PASSWORD_HASH_SHA1);
136 $ldap->update('cn=Hugo Müller,ou=People,dc=my,dc=local', $hm);
142 <sect2 id="zend.ldap.usage.extended">
143 <title>Extended operations</title>
145 <sect3 id="zend.ldap.usage.extended.copy-and-move">
146 <title>Copy and move entries in the LDAP</title>
148 <example id="zend.ldap.usage.extended.copy-and-move.copy">
149 <title>Copy a LDAP entry recursively with all its descendants</title>
151 <programlisting language="php"><![CDATA[
152 $options = array(/* ... */);
153 $ldap = new Zend_Ldap($options);
155 $ldap->copy('cn=Hugo Müller,ou=People,dc=my,dc=local',
156 'cn=Hans Meier,ou=People,dc=my,dc=local',
161 <example id="zend.ldap.usage.extended.copy-and-move.move-to-subtree">
163 Move a LDAP entry recursively with all its descendants to a different subtree
166 <programlisting language="php"><![CDATA[
167 $options = array(/* ... */);
168 $ldap = new Zend_Ldap($options);
170 $ldap->moveToSubtree('cn=Hugo Müller,ou=People,dc=my,dc=local',
171 'ou=Dismissed,dc=my,dc=local',