Codeigniter Design Diagrams

For several years, I worked on Codeigniter, and I just wanted to check out the design patterns. I wanted to implement various design patterns in my work projects in order to better understand these materials.

I know Codeigniter matches the MVC pattern , but which design pattern is codeigniter next?

Is it possible to say database.php, the database class implements the singleton design template? I say, because, as I understand it, a single instance is created on singleton that provides global access, and this is what the CI database configuration object does.

+7
source share
1 answer

Yes, the Codeigniter loader currently follows the singleton pattern, or at least the pattern that most accurately describes it. When you do the following:

$this->load->library('foo'); $this->load->model('foo'); $this->load->database('foo'); 

The loader performs the following actions:

  • Check if a previously loaded class is loaded by checking the registry of loaded classes. You can ignore a request with a debug log entry if it has been loaded.

  • Create an instance of the class with any parameters that you set, create a link to this object in the supermodule (singleton-ish), named after the class, or any ordinary name that you pass. Keep the link, ignore subsequent download attempts.

In bootstrap, magic functions in the global area behind bootloader methods are used to create databases, main libraries, etc.

A more traditional singleton approach could do something like this (with automatic loading):

 return $className::instance(); 

... If the instance method returns an instance or constructs, if it has not yet been created, thus eliminating any need to keep track of what was or was not loaded. If the class has been loaded, a link will be passed, otherwise a new object will be created and returned.

I believe that technically, CI is its own model in this regard, but close enough to the single that this term really applies. This is really a singleton, just not implemented in the usual way.

Finally, I checked that for CI-3 there are patches that make the bootloader more flexible, which allows you to work outside the super-object as you see fit, returning the object or link in these cases, but I don’t know the status of the Ellis lab. taking them.

+6
source

All Articles