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!

4
  • have u load the database also? Commented Jul 19, 2018 at 5:41
  • yes, it is in autoload. Plus I tried to put it here, still crashes on $this->db Commented Jul 19, 2018 at 6:04
  • 1
    i'm not sure if wiredesignz uses ucfirst - take a look here bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/… and here bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/… - maybe you should load your model like $this->load->model('auth/Login_model'); Commented Jul 19, 2018 at 8: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. Commented Jul 19, 2018 at 14:31

2 Answers 2

0

just try this code put in controller:

public function __construct() {

    parent::__construct();


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


}
Sign up to request clarification or add additional context in comments.

2 Comments

this is functionally no different than loading the model directly before using it.
I agree, no difference. Still I tried just for the heck of it, still I have same issue.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.