首页 >后端开发 >php教程 >zend framework class初始化的有关问题

zend framework class初始化的有关问题

WBOY
WBOY原创
2016-06-13 09:59:40746浏览

zend framework class初始化的问题
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();
}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn