Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overwrite CodeIgniter Common.php

Tags:

codeigniter

There is a method in code igniter under system/core/Common.php called load_class().

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

So how exactly do I do this?

like image 963
user391986 Avatar asked Apr 05 '13 12:04

user391986


1 Answers

There's no officially supported way to do this by the built in extending mechanisms. Consider some other way to achieve your goal.

However the functions inside Common.php are all wrapped inside an if checking if the function is already exists or not so you can do the following:

  1. Create your MY_Common.php put somewhere in your project (maybe application/core/ to mirror other similar extends)
  2. Open your index.php file in the root of the project
  3. insert include APPPATH.'core/MY_Common.php'; before the closing
    require_once BASEPATH.'core/CodeIgniter.php'; line

Now if you have you have a load_class function in your MY_Common.php it will shadow the original version.

like image 143
complex857 Avatar answered Nov 09 '22 11:11

complex857