debugging - how to initialize my ldap connection like a doctrine connection in the bootstrap.php file in zend-framework -


i want use ldap server db. create persistence classes in models directory extend zend_ldap won't have write crud operations how can initialize ldap connection in bootstrap.php file
e.g. database connection using doctrine can initialized this, want same 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 want if have thing this(below) in models folder

class application_model_entry extends zend_ldap_node_collection {  public static function getinstance() {     $options = zend_registry::get('config')->ldap;//i want avoid line     $ldap = new zend_ldap($options); // want avoid line     $dn = $ldap->getbasedn(); // want avoid line      $a = new zend_ldap_node_collection(new zend_ldap_collection_iterator_default($ldap,'email')); //also 1      return $a;//where $a instance of ldap entry(node)  } 

then in controller want thing db

$ent = new application_model_entry(); $ent->email = "xyz@abc.xom"; ... $ent->save(); $ent->update(); 

how can initialize ldap connection , access in models possible

you can do

protected function _initldap()  {     $ldap = new zend_ldap(/*... configuration ...*/);     return $ldap; } 

but there no such thing default ldap connection, have retrieve ldap connection object bootstrap's resources. helper class may, well, help.

by way model should not extend zend_ldap - @ least not reason want this. e.g. extend zend_ldap_node representation of single ldap entry, whilst zend_ldap representation of ldap connection , ldap server you're talking to.

edit:

class application_ldap {     public static function getldap()     {         /* return ldap connection bootstrap */     }      public static function newentry($name)      {         $dn   = $name; // build dn given entity name         $node = zend_ldap_node::create($dn);         $node->attachldap(self::getldap());         return $node;     }      public static function loadentry($name)     {         $dn   = $name; // build dn given entity name         $node = zend_ldap_node::fromldap($dn, self::getldap());         return $node     } } 

be advised: not state-of-the-art model, simple solution problem (if understood correctly). allows following in application logic:

$newone = application_ldap::newentry('new-one'); $newone->email = "xyz@abc.xom"; $newone->update();  $oldone = application_ldap::loadentry('old-one'); $oldone->email = "abc@abc.xom"; $oldone->update(); 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -