Home > OS >  Message: Using $this when not in object context codeigniter 3
Message: Using $this when not in object context codeigniter 3

Time:12-20

I want to access my database models from database.php file.

`

//$ci =& get_instance();
        $this->CI->session->userdata('user_id');
        $this->CI->load->model('users/user_model');
        $current_user = $this->CI->user_model->find($this->CI->auth->user_id());
        echo $current_user->organisation;
        $this->CI->load->model('organisation/organisation_model');
        $org =  $this->CI->organisation_model->find($current_user->organisation);

`

CodePudding user response:

Uncomment your first line

$ci =& get_instance();

Then use $ci instead of $this like this

$ci->session->userdata('user_id');

CodePudding user response:

Please use the below code, to access the database model or queries.

$CI = & get_instance();
$CI->session->userdata('user_id');
$CI->load->model('users/user_model');
$current_user = $CI->user_model->find($CI->auth->user_id());
echo $current_user->organisation;
$CI->load->model('organisation/organisation_model');
$org =  $CI->organisation_model->find($current_user->organisation);
  • Related