왜 부모를 사용해야합니까 :: __ construct(); 생성자, 내가 필요로하는 것은 무엇입니까?Codeigniter, 왜 CI_Controller의 구조가 필요합니까? (아래 코드)
// CONTROLLER
class users_ctrl extends CI_Controller {
function __construct() {
parent::__construct(); //Why do I need to include it?
$this->load->model('select_model');
}
public function index()
{
$data['user_list'] = $this->select_model->get_all_users();
$this->load->view('show_users', $data);
}
}
// MODEL하여 주어진 예에서
class select_model extends CI_Model{
function __construct() {
parent::__construct();
}
function get_all_users()
{
$query = $this->db->get('students');
return $query->result();
}
}
가능한 복제 [컨트롤러 클래스는 부모 컨트롤러를 확장 할 때 왜 우리는 여전히 부모 생성자가 필요합니까?] (http://stackoverflow.com/questions/15063890/why-do-we-still-need-parent-constructor- 에서 [CI_Controller 부모] 호출) – skrilled
https://www.codeigniter.com/user_guide/general/controllers.html#class-constructors – user4419336
제어기 - 클래스 --A-C-부모를 확장 할 때 (HTTPS : // GitHub의. com/mattbryson/Codeigniter_Code_Complete/blob/master/system/core/CI_Controller.php # L93) 부트 스트랩 파일 (CodeIgniter.php)에 의해 인스턴스화 된 모든 클래스 객체를 로컬 클래스 변수에 할당하여 CI를 하나의 큰 슈퍼 만약 당신이 자신의 생성자를 가지고 있고 부모 생성자를 호출하지 않는다면, 이것은 일어나지 않을 것이고, 일들은 깨질 것 같다. ('$ this-> load'가 설정되어 있지 않음을 발견하는 것 , 그래서'$ this-> load-> model ('select_mode 난 ');'작동하지 않습니다) –