i want to use my ldap server as a DB. then i will create persistence classes in the models directory that will extend to Zend_Ldap so that i won’t have to write all the CRUD operations but how can i initialize the ldap connection in the bootstrap.php file
for e.g. a database connection using doctrine can be initialized like this, i want to do the same for ldap connection
protected function _initDoctrine()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Doctrine');
$this->getApplication()->getAutoloader()
->pushAutoloader(array('Doctrine', 'autoload'));
spl_autoload_register(array('Doctrine', 'modelsAutoload'));
$manager = Doctrine_Manager::getInstance();
$doctrineConfig = $this->getOption('doctrine');
$manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
Doctrine_Core::loadModels($doctrineConfig['models_path']);
$conn = Doctrine_Manager::connection($doctrineConfig['dsn'],'doctrine');
$conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
return $conn;
}
but now what i want to do is if i have some thing like this(below) in the models folder
class Application_Model_entry extends Zend_Ldap_Node_collection {
public static function getInstance() {
$options = Zend_Registry::get('config')->ldap;//i want to avoid this line
$ldap = new Zend_Ldap($options); // i want to avoid this line
$dn = $ldap->getBaseDn(); // i want to avoid this line
$a = new Zend_Ldap_Node_Collection(new Zend_Ldap_Collection_Iterator_Default($ldap,'email')); //also this one
return $a;//where $a is an instance of an LDAP entry(node)
}
then in the controller i want to do some thing like a db
$ent = new Application_Model_entry();
$ent->email = "xyz@abc.xom";
...
$ent->save();
$ent->update();
how can i initialize the ldap connection and access it in the models so that this could be possible
You can do
But there is no such thing as a default LDAP connection, so you have to retrieve the LDAP connection object from your bootstrap’s resources. Some helper class may, well, help.
By the way your model should not extend
Zend_Ldap– at least not for the reason you want to do this. You could e.g. extendZend_Ldap_Nodewhich is a representation of a single LDAP entry, whilstZend_Ldapis a representation of the LDAP connection and the LDAP server you’re talking to.EDIT:
Be advised: this is not really a state-of-the-art model, but just a simple solution to your problem (if I understood it correctly). It allows you to do the following in your application logic: