简体   繁体   English

如何在Codeigniter中将父类构造函数访问子类

[英]how to access parent class constructor into child class in codeigniter

parent class 家长班

class Main {
          private $ci;
            public function __construct()
    {      
             $this ->ci=& get_instance();
             $this ->ci->load->database();
    }
}

child class 儿童班

   class Commonlib extends main { 

    public function __construct()
    {      
              parent::__construct();
    }
       function getcountries(){
             $this->db->from($this->countries);
             $this->db->order_by("country", "ASC");
             $query = $this->db->get(); 
             return $query->result();

        }
}

i want to access parent constructor variable in child class as child class i use db variable how to access 我想作为子类访问子类中的父构造函数变量我使用db变量如何访问

i want to implement this code show this error

Fatal error: Class 'main' not found

As per class inheritance you should be able to do something similar to parent:: __construct . 根据类继承,您应该能够执行类似于parent:: __construct

As for the error of class class main not found ensure the child class has the correct use statement at the beginning and the autoloader array map has class main mapped. 至于class main not foundclass main not found的错误,请确保子类在开始时具有正确的use语句,并且autoloader数组映射具有class main映射。

http://php.net/manual/en/language.oop5.decon.php http://php.net/manual/en/language.oop5.autoload.php http://php.net/manual/en/language.oop5.decon.php http://php.net/manual/en/language.oop5.autoload.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM