0

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);

`

2 Answers 2

1

Uncomment your first line

$ci =& get_instance();

Then use $ci instead of $this like this

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

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

1 Comment

Thank you! Note that i had to load session library: $CI->load->library('session');
0

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);

2 Comments

Thank you that's correct! theere no space between '=' and '&' at the first line
@saghirSAGHIR it will work with space as well.

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.