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

  • Home
  • SEARCH
  • 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 8770871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:38:47+00:00 2026-06-13T17:38:47+00:00

I have core class in application/core/MY_Lang.php, this class extends CI_Lang class, and overrides contructor

  • 0

I have core class in application/core/MY_Lang.php, this class extends CI_Lang class, and overrides contructor of base class:

class MY_Lang extends CI_Lang {
    function __construct()
    {
        parent::__construct();
    }
}

How i can access to the database object from constructor of my class.

I tried to access CI super object, but class CI_Controller is not loaded for now

    if (class_exists('CI_Controller'))
    {
        $this->CI =& get_instance();
    }
  • 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-13T17:38:48+00:00Added an answer on June 13, 2026 at 5:38 pm

    Ok, looks like I was wrong about being able to just call get_instance().

    But I’ve found a similar post which suggests using a post_controller_constructor “hook” to call your function

    See here: CodeIgniter: get_instance inside My_Lang

    The documentation for Code Igniter hooks is here: http://ellislab.com/codeigniter/user_guide/general/hooks.html

    So I’m guessing that in your application/config/hooks.php file you want to add something like this:

    $hook['post_controller_constructor'] = array(
                                    'class'    => 'MY_Lang',
                                    'function' => '__construct',
                                    'filename' => 'MY_Lang.php',
                                    'filepath' => 'core',
                                    'params'   => array()
                                    );
    

    I haven’t tested this, but let me know if you’re not quite getting it to work and I can put together a proper test.

    Of course, then in the function you specify in your hook is where you’d want to call get_instance() and then load the database library and do whatever work you want.

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

Sidebar

Related Questions

Hi i have these classes: class Core < ActiveRecord::Base belongs_to :resource, :polymorphic => true
I have a program like this - import weka.core.stemmers.SnowballStemmer; public class TestProject{ public static
I have a CORE class that pertains only to my specific site, ie, it
I have a Core Data class Meeting with a property date which I want
I have created a Class Library (Core Processing Component) using C# in Visual Studio
I have a helper class designed to get data from Core Data and pass
I have @Controller @RequestMapping(value=core/*) public class CoreController { public static String exceptionOccurredView = /core/exceptionOccurred;
In my application I have an extended User model called UserProfile. This user can
I have create a getDBConnection method in my Java application. This returns a connection
I'm writing an application on qooxdoo. I have a class, which should return table

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.