• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extending CI (system->application->extention)

Hi everybody,

am new to codeigniter and just am looking for some feedback on my solution to extend codeigniter (maybe it might even be of interest to somebody). Sorry for the length of the post, but I am trying to be clear about I am trying to do. Just to clarify this seems to work, I'm just wondering if there is a better way. Warning: ONLY BASIC TESTING HAS BEEN DONE.

Some background: I am currently rewriting a system we are using with multiple clients. The system was originally built as a bespoke solution for one client. Other companies approached us about it, each requiring some bespoke modifications. Currently that means changes to the code for each clients, which as you can imagine is a big pain (thank god for SVN). So what I need is:

1) To be able to overwrite/extend my basic application with the clients bespoke changes. Currently CI looks for files in application, then system. I need it to look in extention, then application, then system.

2) As I am currently not sure which core or application controllers/models/views/libraries/helpers/config I will need to extend, all of these should be extendable. Hooks/errors/language files are unlikely to require extending, so are ignored for the moment.

Approach: I realised some changes to the core were probably required, although the aim is to keep these to an absolute minimum. I considered putting my application directly into the systems folders, but I wasn't sure how then to deal with controllers/models/views. Plus I figured, as our system is pretty big, this would just lead to bigger problems in the future with loads of my files being mixed up with core files. Finally extentions to the core libraries I would want to make, might then have to be done directly in the core file.

So I had a look at how CI loads the various elements and found the following files needed changing. Feedback is welcome. If anybody can tell me how to do this without touching the core, I would love to hear.

root/index.php: requires path to extention folder and define a constants.

root/system/codeigniter/Common.php: load_class() has to be changed to also look in extention folder, if required.

root/system/codeigniter/CodeIgniter.php: changes to main controller call (line 150+) so the right path and name for the controller are specified.

root/system/application/config/config.php: new 'subsubclass_prefix' setting, plus code to read config file of same name in extention folder (which can be used in any config file)

root/system/application/libraries/MY_Router.php: amend _validate_request() and add some new set and fetch functions

root/system/application/libraries/MY_Loader.php: amend model(), helper(), _ci_load() & _ci_load_class

The amended and new files are in the attached zip.

Thanks for any comments

I'm confused... CI is a framework, and as such is built to be extended, that's the entire purpose of the "application" folder... Furthermore any extension can be placed in a subfolder (or subfolders), so I'm not really seeing the purpose? Maybe you can explain the difference between the core functionality and what you're trying to accomplish? Or provide an example?

Let me try and rephrase it. There are 3 levels:

Level 1: Core CI (ie the framework; e.g. root/system/libraries/Benchmark.php)

Level 2: Application (e.g. root/system/application/libraries/MY_Benchmark.php)

Level 3: Project/Extention (e.g. root/project_folder_name/libraries/ext_Benchmark.php)

In this example, if the Benchmark library is called, it first looks in level 3 (new), then level 2 (as normal) and then level 1 (as normal).

Additionally is should use the same rules regarding extending/overwriting as CI.

I forgot to mention that in my code all changes are marked:

extention change

I thought it might be a bit clearer if I included some test files. Here is the code again, with a load of test controllers, models, views, libraries, helpers and config files. Any file with test in the file name is there purely for testing.

If you look at the files you will notice that there is a root/extention/ and a root/system/application/ folder.

Again all actual changes to how CI works are marked with:

extention change

Maybe I am approaching this from completely the wrong angle. Comments would be greatly appriciated.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.