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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:49:16+00:00 2026-05-30T03:49:16+00:00

I am trying to build my own simple MVC framework, mainly for educational purposes

  • 0

I am trying to build my own simple MVC framework, mainly for educational purposes than anything else, I have used CodeIgniter in the past which has provided most of the inspiration for the features I would like to incorporate into my framework.

I would like to build a loader class like CodeIgniters, but I can’t understand how CI loads the classes as if they are properties of the calling class i.e

class Random_Controller{

    function __construct(){
    $this->load->helper('some_class');
    $this->some_class->do_something();
    /*
    How does CI load some_class as if it were a property of Random_Controller?
    I can understand using something like $$class_name = new $class_name();
    Or $$this->class_name = new $class_name();
    But how can the dynamically named object be used with $this->?
    */
    }
}

Hopefully that makes sense…

I am always surprised at how simple things appear with the right explanation. One more question though.

If $load is a reference to an instance of load class, and a record of all loaded classes is kept in an array, we are essentially doing:
$this->loaded_classes[$key]->do_something()?

So how does CI resolve the array to a variable name? I have seen some PHP magic methods that are called when variables do not exist or methods do not exist, would this be done in conjuction with these magic methods? In other words if the $this->some_class property does not exist we search for an element in the array with that key?

If that makes sense..

  • 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-30T03:49:18+00:00Added an answer on May 30, 2026 at 3:49 am

    Uhm, well, let’s start with this: the CI_Controller super class; it’s the one all controllers extends, and acts as the CI superobject all the $this refer to.

    CI_Controller acts as a singleton, and during initializing it calls a function, load_class() (you can find in core/common.php) which works as an autoloader : inside a static array ($_classes) it assignes as index the class name, and as value the class instance:

    $_classes[$class] = new $name();
    

    Then the companion is_loaded() function (in the same file) registers in an array all the function loaded, and is used to check later if the class has already been instantiated or not.

    Ci_Controller assigns then to its $load property an instance of the Loader class (core/loader.php, by using the above mechanism)

    $this->load =& load_class('Loader', 'core');
    

    which, in turn, is responsibile for loading all other resources using its own methods: helper(),library(),model() and so on. Have a look at the source for all details, hope you got the picture though

    To clarify as per your comment:

    $load = new Loader();
    $load->helper('helper');
    

    would be the same as:

    $this->load->helper('helper'),

    as $this->load contains an instance (by reference) of the Loader class.
    Then how the helper(),library(),etc methods of the Loader class work would be too much to write here, and beside you can open up the Loader.php file and have a look by yourself.

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

Sidebar

Related Questions

I'm trying to build my own template tags. I have no idea why I
Just for my own purposes, I'm trying to build a tokenizer in Java where
I'm trying build a MVC framework, but I'm confused about manage themes. Well... I
Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs
I am trying to build my own simple template handler to easily be able
I am trying to build my own module in Drupal 7. So I have
I'm trying to build my own simple rich editor, so far so good. I
I am trying to build my own zend module (.so) We have multiple functionality
I'm trying to build my own custom django form widgets (putting them in widgets.py
I am trying to build my own little toolbox for Vista. One of the

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.