0

I use CodeIgniter 3 with HMVC.

Does anyone know why do I get the following error

    Severity: Notice
    Message: Undefined property: Login::$login_model

On the second line below. I clearly call the model, but for some odd reason it is not linked properly

    $this->load->model('auth/login_model');
    $response = $this->login_model->attempt($username, sha1($password));

Then the model is pretty basic :

    <?php
    class Login_model extends CI_Model 
    {
        public function attempt($user, $pass) 
        {
        ... 

Now if I use an object it works, but I have the same issue in many places, including the place where I have

    $this->db->select("....

where is crashing as there is no "db". What is the new solution for CodeIgniter 3? I've seen older posts, but none seem to help me out

Thanks!

Pradeep
  • 9,667
  • 13
  • 27
  • 34
Marius
  • 190
  • 1
  • 9
  • have u load the database also? – Pradeep Jul 19 '18 at 05:41
  • yes, it is in autoload. Plus I tried to put it here, still crashes on $this->db – Marius Jul 19 '18 at 06:04
  • 1
    i'm not sure if wiredesignz uses ucfirst - take a look here https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/src/f77a3fc9a6fdbfa47d70c921dac31d6d29a664e6/third_party/MX/Loader.php?at=codeigniter-3.x&fileviewer=file-view-default#Loader.php-198 and here https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/src/f77a3fc9a6fdbfa47d70c921dac31d6d29a664e6/third_party/MX/Modules.php?at=codeigniter-3.x&fileviewer=file-view-default#Modules.php-145 - maybe you should load your model like `$this->load->model('auth/Login_model');` – Atural Jul 19 '18 at 08:10
  • thanks @sintakonte, you got me closer. I already tried to capitalize, but the links you sent me were very useful as I started to debug the loader routine. And found my answer that way. – Marius Jul 19 '18 at 14:31

2 Answers2

0

just try this code put in controller:

public function __construct() {

    parent::__construct();


    $this->load->model('Login_model'); // load model 


}
Jaydev Vara
  • 45
  • 4
  • 19
0

Problem is resolved, the issues were caused by the fact that my controller extended CI_Controller instead of MX_Controller. So changing

       class Login extends CI_Controller 

to

       class Login extends MX_Controller 

resolved the issue.

It took me a while to figure it out by debugging the thirdparty/MX/Loader.php, but once I saw it was looking for MX_Controller type I did the change and it worked perfectly.

This issue is one in many related to migration from CI 2 to CI 3 and also using the HMVC from Wiredesignz. Another big one is uppercase of file names and uppercase on the calls, so strictly referring to this issue I had to uppercase the calls in my controller (changed "login" to "Login"):

     $this->load->model('auth/Login_model');
     $response = $this->Login_model->attempt($username, sha1($password));

I did the above change already, so this was no longer a blocker, still I wanted to put it here just in case someone hits the exact same issue

Thanks all for your help

Marius
  • 190
  • 1
  • 9