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 8698013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:39:05+00:00 2026-06-13T01:39:05+00:00

Basically in codeigniter, how can i use the system and application libraries within other

  • 0

Basically in codeigniter, how can i use the system and application libraries within other libraries? So say I have a application library such as:

class User
{
   // some instance variables
}

Now lets say I want to use codeigniter session class in the User class, basically being able to work with sessions inside the User class. How can I go about doing this?

  • 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-06-13T01:39:06+00:00Added an answer on June 13, 2026 at 1:39 am

    The typical way to do this is to use get_instance(), which returns an instance of Codeigniter (actually the current controller class).

    This will work from anywhere in your CI application:

    get_instance()->session->set_userdata('key', 'value');
    $segments = get_instance()->uri->segment_array();
    // etc.
    

    Typically in Codeigniter, you assign it to a class variable for ease of use:

    class User
    {
        private $CI;
    
        function __construct()
        {
            $this->CI = get_instance();
        }
    
        // Example
        function login()
        {
            $user = $this->get_user();
            $this->CI->session_set_userdata('user_id', $user->id);
        }
    }
    

    This does create a lot of dependency on the state of CI and the different loaded classes, rather than passing instances of them in directly to the User class via Dependency Injection, but this is the typical flow for someone developing a CI library.

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

Sidebar

Related Questions

With CodeIgniter you can use the built in form validation class, which basically allows
Basically, I have a CodeIgniter site that registers users through this url: http://website.com/user/register/1 Unfortunately,
I have a question about PHP foreach loops. I'm using it in Codeigniter. Basically
I am using codeigniter php MVC framework to develop a web application. I have
Basically I have two controllers using CodeIgniter for a simple blog for a project
I have an installation of CodeIgniter. Basically, my directory structure looks like this: |
I can't figure out how to do the url links. Basically I have my
I am using CodeIgniter, and basically a PHP noob. So I have this table
Hi I'm developing a CodeIgniter application that gives user their own website. What I'm
I have used Codeigniter for several years and now use it with Modular Extensions

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.