10/10/2018, 11:07
[CI] Rắc rối chỗ thừa kế
Ta có class system:
1 class cont_model:
Trong class content:
Class content và system nằm trong thư mục Controller, 'cont_model' nằm trong thư mục model.
Khi chạy thì nó báo lỗi thế này:
Cho em hỏi cách xử lí và sai ở chỗ nào.
Cảm ơn các bạn nhìu
Code:
<?php
class system extends controller{
function system(){
parent::Controller();
$this->load->model('cont_model');
}
function view(){
$this->cont_model->display();
}
}
Code:
<?php
class cont_model extends model{
function cont_model(){
parent::Model();
$this->load->library('library');
}
function display(){
echo 'hello';
}
}
Code:
<?php
include_once('system.php');
class content extends controller{
function content(){
parent::Controller();
$this->load->model('cont_model');
}
function index(){
$s = new system();
$s->view();
}
}
Khi chạy thì nó báo lỗi thế này:
Code:
Fatal error: Call to a member function get() on a non-object in E:phpsuperbargainsystemapplicationcontrollerssystem.php
Cảm ơn các bạn nhìu
Bài liên quan





à mà dùng Ci 1.7 hay 2.0
2.0 nó xài hàm __contruct mà
sao mấy bác bây giờ vẫn xài cái hàm khởi tạo đặt tên giống class của php4?
<?php include_once('system.php'); class content extends system{ function content(){ parent::Controller(); //$this->load->model('cont_model');//ko cần gọi vì system load model rồi } function index(){ //$s = new system(); //$s->view(); $this->view(); } }Bạn có thể giúp mình được ko, tại mình hơi mù chỗ này. Thanks bạn
//class a class A extends Controller { function A (){ parent:: Controller(); $this->load->model('a_model'); } function fn_of_a(){ //do something... } } //class b require_once 'a.php'; class B extends A { function B(){ $this->load->model('b_model'); } function fn_of_b(){ //do something 2 } } //class C require_once 'B.php'; class C extends B{ function C(){ $this->load->model('c_model'); } function fn_of_c(){ $this->fn_of_a(); $this->fn_of_b(); } } classNếu bạn bắt đầu học CI thì nên tìm hiểu HMVC của CI.