Zendframeworkclass initialization problems

Source: Internet
Author: User
Zendframeworkclass initialization & lt ;? PhpclassDbextendsZend_Db_Table {function _ construct ($ name, $ primary) {echo & quot; ****** $ name ****** & quot ;;} publicfunctionsetName (zend framework class initialization problem
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 ');

}

Result
***********
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


------ Solution --------------------
In the inheritance class of zend_db_table, it is better not to use the constructor. use another method similar to the constructor.
Protected function _ setup ()
{
$ This-> _ name = 'Category ';
Parent: _ setup ();
}
------ Solution --------------------
If you must use the constructor, remember to call the constructor of the parent class in the subclass.
Public function _ construct ($ name, $ primary)
{
$ This-> _ name = $ name;
$ This-> _ primary = $ primary;
Parent: :__ construct ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.