Welcome Guest, Not a member yet? Register   Sign In
MY_Controller can't load model in HMVC
#1

[eluser]didit[/eluser]
hi all,

i have a problem with MY_Contoller, why it can't load model ?? im using modular extention

here is my codes :
Code:
class MY_Controller extends Controller {

    function MY_Controller ()  {
        parent::Controller();
    }
}
note : I locate it in ci/system/application/libraries/

my controller
Code:
class Testing extends MY_Controller {
    
    function Testing() {        
        parent::MY_Controller();        
        $this->load->model('testing_model');
    }
      
    function getall() {          
        $data['items'] = $this->testing_model->getAll();                    
    $this->load->view('viewemployee',$data);
    }
}

my model
Code:
class Testing_Model extends Model {
      
    function Testing_Model() {        
        parent::Model();        
    }
    
    function getAll() {  
        $sql = "some query";
        $query = $this->db->query($sql)->result_array();        
        $items = array();
        foreach ($query as $row) {
            $items[] = $row;
        }                        
    return $items;
    }
}

an error occurred when i run http://localhost:81/ci/index.php/testing/getAll
here is the error :
Quote:An Error Was Encountered
Unable to locate the model you have specified: testing_model

plese help !
just FYI, everything works fine if i don't use MY_Controller
sorry im not good enough in english Big Grin
#2

[eluser]Colin Williams[/eluser]
Your model should be "Test_model" and not "Test_Model" and the filename should be test_model.php

CI is case sensitive
#3

[eluser]didit[/eluser]
hi collin,

I have change my model to Testing_model and filename to testing_model, but the same error still occured !

please advice, thanks
#4

[eluser]flaky[/eluser]
From the wiki
Quote:Use application/libraries/MX_Controller.php to contain Controller class extensions instead of using MY_Controller.

Use application/libraries/MX_Loader.php to contain Loader class extensions instead of using MY_Loader.
#5

[eluser]didit[/eluser]
yup, it's work, thanks flaky Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB