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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:08:30+00:00 2026-05-22T23:08:30+00:00

I come from a Java background and I am now trying to study PHP

  • 0

I come from a Java background and I am now trying to study PHP for a web project I am doing on the side written in CodeIgniter. Right now I am trying to study how to use CI’s models. I am naturally very curious about reading framework code to gain a deeper understanding of how the tools I am using work.

I am really confused as to where the the “$db” in “$this->db” comes from in the Model classes that extend CI_Model come from. I checked the CI_Model class itself but it is not there.

Prior to this I have read the CI_Controller’s code and somehow reckon that the although the $this->load->model(….) is not an instance variable ($this->load) with a method model(…_), somehow “it is there” because the constructor instantiates a $this->load instance variable in the constructor (the Loader class found in the core/ folder which has a model(…) function.

But for the $CI_Model I don’t see the same thing. Where does the “$this->db” being referenced and when is it loaded?

  • 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-22T23:08:31+00:00Added an answer on May 22, 2026 at 11:08 pm

    I’ve not studied the code hard enought, but I’ve been using codeigniter for a while, I hope not to say something wrong, but things doesn’t work as you guessed. The $db you’re looking for is not in the CI_Model superclass (nor in the CI_Controller superclass), but it’s a variable declared in the Loader class (system/core/loader.php).

    A codeigniter application is designed to work as if it were a giant “superclass”, in fact all libraries and models and so on are instantiated using $this (which usually is used in the scope of a class), so when you’re loading the db library – and you can do it in your models but also in your controllers (and, if you instanciate the main $CI class in a custom library, also there) – you’re in fact referring to a variable create in the loader class, precisely in line 229 (more or less) inside the database method of the CI_Loader class.

    I’m not so deep in CI knowledge to give you better details, but if you take a look at the codeigniter.php and loader.php you can get enough insights to underdstand how CI internally works.

    If you have other question or something’s still not clear just ask 😉

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

Sidebar

Related Questions

I come from a C, C++, and Java programming background, now getting my feet
I come from a web development background and haven't done anything significant in Java
I come from a Java background, where packages are used, not namespaces. I'm used
I come from a Java background and with any servlets-based technology, it's trivial to
I come from a java background. But I would like a cross-platform perspective on
I come from more of a Java background. In the last year or two,
I come from a mainly PHP background and make good use of the Apache
I come from a CVS background. I'm currently investigating using SVN for a project.
I come from a .NET background and am completely new to Java and am
I come from a C/C++ background and now do a lot of C# stuff.

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.