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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:23:06+00:00 2026-06-08T08:23:06+00:00

I have a philosophic question on CodeIgniter, and the role of its model on

  • 0

I have a philosophic question on CodeIgniter, and the role of its model on the utilisation of “new” to instance something.

It looks to me that the idea, is that you use for example to use let say a model of a book

$this->load->model("book_model")

instead of

new book_model

What I mean, is that since you load only once the book_model, you will have only one instance of a book_model, and if you want to model multiple books, you will use a createNewBook function in the book_model, instead of going through the _construct fonction after using “new”.

Is it right to see it like this? I mean to consider that I use the same instance of book_model and a function inside it “initiateBook”? Should we consider to never use “new” in CodeIgniter?

  • 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-08T08:23:07+00:00Added an answer on June 8, 2026 at 8:23 am

    Actually when you call $this->load->model("book_model") the CodeIgniter does the job for you, which means CodeIgniter‘s Loader class has a method public function model(...) which instantiate the model that you’ve passed as an argument, for example book_model here.

    Taken from model function in Loader class (located in system/core)

    if (in_array($name, $this->_ci_models, TRUE))
    {
        return;
    }
    

    It checks the _ci_models protected array to see if the requested model is already loaded then it returns and if it’s not loaded then it loads it, i.e. (the last segment of model method)

    $CI->$name = new $model(); // here $model is a variable which has the name of the requsted model
    $this->_ci_models[] = $name; // stores the instantiated model name in the _ci_models[] array
    return; // then returns
    

    So, you don’t need to use new to instantiate it manually and once a model (same applies with other libraries or classes) is loaded then you can access/use it anywhere in your script.

    Since CodeIgniter uses the Singleton (an answer on SO about singleton pattern) design pattern so you have only one super global $CI object (one instance of CodeIgniter) available and it carries everything you’ve loaded or you’ll load.

    To load the book_model model and then call the initiateBook() method of that model

    $this->load->model("book_model"); // book_model loaded/instantiated
    $this->book_model->initiateBook(); // initiateBook() function has been called
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is something of a philosophical question, but one I hope to have answered
I have an encryption/copy protection question. I'm writing an application for a company that
Bit of a philosophical question. If you have a public website with a site
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I recently asked another question pertaining to avoid having to use boilerplate exceptions when
I have sort of a philosophical question, which also need to consider the performance
I guess this is sort of a philosophical question, but I have some code
I have a large dataset of philosophic arguments, each of which connect to other
I'm teaching myself Scala and I have sort of a philosophical question. Is pattern
Philosophical question: Say I've got a web app that requires javascript and a modern

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.