我想將我的ldap服務器用作數據庫。那麼我將在模型目錄中創建持久化類,擴展到Zend_Ldap,以便我不必編寫所有CRUD操作,但是如何初始化bootstrap.php文件中的ldap連接
,例如,使用學說數據庫連接可以這樣初始化,我想爲LDAP連接如何在zend-framework中的bootstrap.php文件中初始化我的ldap連接,如教條連接
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;
}
做相同的,但現在我想要做的是,如果我有一個像這樣(下圖)的一些事情在模型文件夾
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)
}
然後在控制器我想要做一些事情如DB
$ent = new Application_Model_entry();
$ent->email = "[email protected]";
...
$ent->save();
$ent->update();
我怎麼能初始化模型中的LDAP連接和訪問它,這可能是可能的
我試過那個。但是你能解釋一下你的答案嗎?當你說「但是沒有這樣的東西作爲默認的LDAP連接時,所以你必須從引導程序的資源中檢索LDAP連接對象,有些輔助類可能會幫助你.........「b/se我想避免我上面指出的行,將它們移動到bootstrap.php文件中,如您所示。即使我已將該行移至bootstrap.php文件已經如何以相同的方式訪問連接異議,如同教條或左右..在模型@Stefan Gehrig – jspeshu 2010-10-10 12:39:02
我的意思是*但沒有這樣的事情作爲默認LDAP連接*是,儘管Doctrine對默認數據庫連接維護靜態全局引用(使用單例),並在生成的模型中使用此引用以允許與數據庫進行交互,而無需每次指定明確的連接,但「Zend_Ldap」本身自己並沒有這樣的概念。它並不是爲基於LDAP的數據設計某種對象關係映射器,表格網關或行網關。它可以與'Zend_Db'在其核心部分進行比較:提供一個接口到... – 2010-10-11 07:13:24
...數據庫連接。我會擴展我的答案以展示一種可能的方法。 閱讀你的編輯,我覺得你應該看看'Zend_Ldap','Zend_Ldap_Node'和'Zend_Ldap_Node_Collection'代表什麼。你在混合這些實體。 – 2010-10-11 07:15:18