편집 : 아래 OP 최초의 코멘트에 관해서
...
내가 모듈 DB 리소스 설정에 정성 들여 질수 없음.하지 내가 제공 한 것은 내가 믿는 이론에서 작동해야한다. 만약 내가 그 리소스를 사용하지 말아야 elfted Zend_Application_Resource_Db
의 확장에 수정해야할지 모르겠다. 고유 한 연결 이름을 기반으로 db db 연결을 가져올 수있는 자체 사용자 지정 리소스가 있습니다.
이
class MyLib_Db extends Zend_Db
{
protected $_instance = null;
protected $_connections = array();
/**
* Standard Zend Framework unified constructor
* @param null|array An array of options that will be passed to setOptions
*/
public function __construct($options = null)
{
}
/**
* Standard Zend Framework setOptions implementation
* @param array $options and array of options from config
* @return MyLib_Db
*/
public function setOptions(array $options)
{
}
/**
* Set the class instance
* @param MyLib_Db
* @return MyLib_Db
*/
public static function setInstance($instance)
{
}
/**
* Get/create the singleton instance
* @return MyLib_Db
*/
public static function getInstance()
{
}
/**
* Get a Zend_Db adapter Instance by unique name
* Searches self::$_connections for the $name param as an array key
* @param String $name unique connection name
* @return Zend_Db_Adpater_Abstract|null
*/
public function getConnection($connectionName)
{
}
/**
* Add a connection instance to the registry
* Adds/creates an Zend_Db_Adapter instance to the connection registry with
* the string key provided by $name. If $connection is an array|Zend_Config it
* should match the format used by Zend_Db::factory as it will be passed to this
* function. If $name is null then the database name will be used.
* @param Zend_Db_Adapter_Abstract|Zend_Config|array The connection to register
* @param string|null $name A unique name for the connection
* @return MyLib_Db
*/
public function addConnection(Zend_Db_Adapter_Abstract $connection, $name = null)
{
}
/**
* Remove/Destroy the specified connection from the registry
* @param string $name the connection name to remove
* @return MyLib_Db
*/
public function removeConnection($name)
{
}
}
그래서 기본적으로 DB에 대한 내 응용 프로그램 리소스를 생성하고 선행하는의 인스턴스를 반환 : 그러나 나는 그래서 그것을 이런 식으로 뭔가를 보이는 Zend_Db
를 확장하는 MyLib_Db
클래스가 그 :-)
에 ellaborate 수 있습니다 수업. 생성하는 동안 구성에 설정 한 모든 어댑터를 만들고이 클래스 인스턴스에 이름을 등록합니다 (또한 Zend_Db_Table
과 함께 사용할 기본 플래그를 찾고 일부 다른 작업을 수행함).
그런 다음 MyLib_Db::getInstance()->getConnection($name);
을 사용하거나 부트 스트랩에서 MyLib_Db
인스턴스를 얻은 다음 getConnection
을 호출하십시오.
개인적으로 나는이 방법을 선호합니다. 연결이 넓어 지거나 더 유연한 재사용이 가능한 특정 모듈에 연결되어 있지 않기 때문입니다. 저의 Zend 프로젝트 대부분이 Zend_Db
대신 Doctrine을 사용했기 때문에 저는 실제로이 프로젝트를 몇 개의 프로젝트에만 사용했다고 말했습니다.
이 사실 난 당신이 modules.terms.resources.db.*
같은 설정에서 모듈의 섹션에 그것을 넣어 필요가 있다고 생각 :-) 도움이
희망. 이렇게하면 모듈 부트 스트랩에로드됩니다. 또는 Terms_Bootstrap
에 _initDb
으로 설정할 수 있습니다.
개인적으로 나는 특별한 DB 관리 클래스를 사용하고 대신 내 리소스에 넣습니다. 단일 또는 다중 어댑터 설정을 처리합니다. 다음에 $db
이 자원 배열에서 검색된 관리자임을 나타냅니다.
$dbAdapter = $db->getConnection('terms');
의 경우에 알려 주시기 바랍니다. 부트 스트랩 내에서 설정하는 방법에 대해 자세히 설명해 주시겠습니까? – Tamlyn
@ Tamlin : 위의 편집을 참조하십시오. – prodigitalson