Using class in model - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: Using class in model (/showthread.php?tid=67898) |
Using class in model - -V1cu- - 04-21-2017 Hey guys, I have a weird problem and i can't figure out how to solve it... I have a custom library User.php with de following code: PHP Code: defined('BASEPATH') OR exit('No direct script access allowed'); And the model Users_model.php with the following code: PHP Code: defined('BASEPATH') OR exit('No direct script access allowed'); The problem is that in the model at method login_remembered_user i get the error that class user isn't set, although the user library is autoloaded... What i'm doing wrong? RE: Using class in model - neuron - 04-21-2017 As I know $this in library does not reference to CI, it references library class itself. Thus in your code $this->load within library you need to get instance of CI so instead of: Code: $this->load->model('users_model'); Quote: RE: Using class in model - -V1cu- - 04-21-2017 (04-21-2017, 03:34 AM)neuron Wrote: As I know $this in library does not reference to CI, it references library class itself. For this in the user library is the following method: PHP Code: public function __get($var) |