Search code examples
phpcodeignitercodeigniter-3ion-auth

How to load ion auth model in codeigniter HMVC


I am using the ion auth library for the CodeIgniter HMVC, I have copied all files from ion auth library to main CodeIgniter files but the controller, model, and views files copy to module directory Now it's showing me this error.

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Auth::$ion_auth_model

Filename: libraries/Ion_auth.php

Line Number: 122

Backtrace:

File: /opt/lampp/htdocs/CI_Hmvc/application/libraries/Ion_auth.php Line: 122 Function: _error_handler

File: /opt/lampp/htdocs/CI_Hmvc/application/libraries/Ion_auth.php Line: 70 Function: __get

File: /opt/lampp/htdocs/CI_Hmvc/application/third_party/MX/Loader.php Line: 173 Function: _ci_load_library

File: /opt/lampp/htdocs/CI_Hmvc/application/third_party/MX/Loader.php Line: 192 Function: library

File: /opt/lampp/htdocs/CI_Hmvc/application/third_party/MX/Loader.php Line: 153 Function: libraries

File: /opt/lampp/htdocs/CI_Hmvc/application/modules/home/controllers/Auth.php Line: 9 Function: library

File: /opt/lampp/htdocs/CI_Hmvc/index.php Line: 315 Function: require_once

could anybody tell me how to load the model, when I work as modules?


Solution

  • I believe the problem is that the library is not finding the model. Check inside ion auth library construct. Look for the line where it says

       $this->load->model('ion_auth_model'). 
    

    It should be line 122 since that's where the error is ocurring. In here you need to prefix the module name - where you have the ion_auth_model - to the model path so the loader class knows where to find it.

    In your case if the module's name is directory, then 'directory/ion_auth_model'.

    Check this solution https://stackoverflow.com/a/7003180/5785088, point 10, last item. Hope it helps.