Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7186147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:34:15+00:00 2026-05-28T18:34:15+00:00

When a user is logged into my CodeIgniter application, I need a list of

  • 0

When a user is logged into my CodeIgniter application, I need a list of profiles that they have to be in the menu on every page they visit. Rather than call the model function on every single method in my application like so:

if ($this->users_model->is_logged_in())
{
    $data->profiles = $this->profiles_model->get_profiles();
}

$this->load->vars($data);

Is there a better way to do this? I considered the option of extending the CI_Controller class like this also but could not determine how best to pass the variable onto the actual method that will need the information.

class MY_Controller extends CI_Controller
{
    public function __construct()
    {
        // Alternatively these could be auto-loaded
        $this->load->model(array('profiles_model', 'users_model'));

        if ($this->users_model->is_logged_in())
        {
            $data->profiles = $this->profiles_model->get_profiles();
        }
    }
}

My concern lies with best practice, best performance and best ability to cache (if this is even possible).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:34:16+00:00Added an answer on May 28, 2026 at 6:34 pm

    If I have anything that I need on all pages I do the following.

    1. Add a helper.
    2. Add your new helper to autoload.
    3. Simply call your function where ever you need to.

    The reason I do this, is the because if you need it on many different controllers then having it in one easily accessible place is very handy. When you need to maintain your code it will make it a lot easier too. For example, if you want to add in caching then you can just add that code into that single function instead of having to change it in every controller.

    Infact, in your specific case, I actually created my own session class to extend the CI Session. As a very basic example (I also use sessions in database for this):

    class MY_Session extends CI_Session {
        public function __construct() {
                parent::__construct();
        }
    
        public function login($email, $password) {
            $CI =& get_instance();
            $CI->load->model('usermodel', 'user');
    
            $result = $CI->user->login($email, $password);
    
            if($result === false) {
                return false;
            } else {
                $this->set_userdata('email', $result->email);
    
                return true;
            }
        }
    
        public function is_logged_in() {
            $email = $this->userdata('email');
    
            if(!empty($email)) {
                return true;
            } else {
                return false;
            }
        }
    }
    

    This way, since you are probably storing this information in sessions, it makes a lot of sense to keep that information together.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pop-up window a user logs into, once they are logged in
I have a rails app, that when a user is logged into his account,
The issue here is that when my user logs into my app, they always
Suppose I have logged into an application which is running from IIS . Now
Logged into my Windows XP SP2 computer using my normal user account (which has
I have the following class which handles my user logged in / logged out
How would you ensure that only one user is logged in per account at
I keep a Session variable when the user is logged in. So that when
I currently have code in my ApplicationController to check if a user is logged
This is crazy, but I'm stumped! Once my user has logged into twitter via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.