家长班
class Main {
private $ci;
public function __construct()
{
$this ->ci=& get_instance();
$this ->ci->load->database();
}
}
儿童班
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();
}
}
我想访问子类中的父构造函数变量作为子类,我使用db变量如何访问
i want to implement this code show this error
Fatal error: Class 'main' not found
根据类的继承,您应该能够执行类似的操作parent:: __construct
。
至于类的错误,请class main not found
确保子类在开始时具有正确的use语句,并且自动加载器数组映射具有类main映射。
http://php.net/manual/en/language.oop5.decon.php http://php.net/manual/en/language.oop5.autoload.php
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句