我正在研究将支持多种数据库方法的MPTT对象。首先是MySQL和MySQLi。现在,我已经创造了它这样返回对象实例的引用
MPTT - 主要对象,将加载正确的子对象
class Mptt {
/**
* Array of available driver types
* @var array
*/
private $availableDrivers = array('mysqli','mysql');
/**
* Holding an instance of the mptt object corresponding to the selected driver
* @var object
*/
public $instance;
public function __construct($driver = 'mysqli', $autoConnect = false, $info = array()) {
if (in_array($driver, $this->availableDrivers)) {
switch ($driver) {
case 'mysqli':
$this->instance =& new Mptt_MySQLi();
break;
case 'mysql':
$this->instance =& new Mptt_MySQL();
break;
}
return $this->instance;
}
}
}
现在,我已经全成在得到这个工作的唯一方法是像做
添加公共变量为每个驱动程序,并像这样做
$mptt = new Mptt('mysqli');
$mptt->mysqli->addBranch(.....);
,但我不希望mysqli-> part
..所以我想如果我也许试图将$this->instance
通过作为REFFERENCE然后$mptt
将reffer到Mptt_MySQLi
代替..
希望有人知道一个答案..
预先感谢 - 奥莱
看看这个:http://components.symfony-project.org/dependency-injection/ – Mchl