Overwrite Common.php code igniter

In the code igniter, there is a system / core / Common.php method called load_class ().

I would like to rewrite this method. Usually, to overwrite the code igniter class, I create a file such as MY_Common.php , however in this case, Common.php is a set of methods and there are no classes that encapsulate them.

So how exactly do I do this?

+6
source share
2 answers

An officially unsupported way to do this is with built-in extension mechanisms. Think of another way to achieve your goal.

However, functions inside Common.php wrapped inside if if the function already exists or not, so you can do the following:

  • Create your MY_Common.php placed somewhere in your project (perhaps application/core/ to reflect other similar extensions)
  • Open the index.php file in the project root directory
  • insert include APPPATH.'core/MY_Common.php'; before closing require_once BASEPATH.'core/CodeIgniter.php'; line

Now, if you have the load_class function in MY_Common.php , it obscures the original version.

+10
source

The correct / official way to do this is to rewrite the main common function in ie. common_helper.php application/helpers and setup in config/autoload.php

+1
source

All Articles