Home > Backend Development > PHP Tutorial > zend framework class初始化的有关问题

zend framework class初始化的有关问题

WBOY
Release: 2016-06-13 13:49:04
Original
746 people have browsed it

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();
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template