日期:2014-05-17  浏览次数:20727 次

zend framework class初始化的问题
<?php
class Db extends Zend_Db_Table {
function __construct($name='',$primary=''){
echo "*****$name******";
}
public function setName($name){
$this->_name = $name;
}
public function setPrimary($primary){
$this->_primary = $primary;
}
}

function indexAction(){
$artiClass = new Db('b_arti_class','id');

}

的结果
***********
Catchable fatal error: Argument 1 passed to Zend_Db_Select::__construct() must be an instance of Zend_Db_Adapter_Abstract, null given, called in D:\Soft\wamp\www\library\Zend\Db\Table\Select.php on line 76 and defined in D:\Soft\wamp\www\library\Zend\Db\Select.php on line 163


------解决方案--------------------
在zend_db_table 的继承类里面最好不要用构造器,用另外一个类似构造器的方法
protected function _setup()
{
$this->_name = 'category';
parent::_setup();
}
------解决方案--------------------
如果你一定要用构造器,记得在子类中调用父类的构造器
public function __construct($name,$primary)
{
$this->_name = $name;
$this->_primary = $primary;
parent::__construct();
}