![](/img/trans.png)
[英]How to implement protected parent class field from child class in Codeigniter constructor
[英]how to access parent class constructor into child class in codeigniter
家長班
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
類class 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.