Search code examples
phpcodeignitercodeigniter-2

CodeIgniter core library extensions within subfolders


I am curious if it is possible to organize library extensions within subfolders of the libraries directory within codeigniter application.

For example lets say we want to extend the 'Form_validation' library. The default way to extend this core library would be to create a class with the same name prepending 'MY_', and saving it as follows:

/application/libraries/MY_Form_validation.php

Now let's say we want to keep all of our extended libraries we have created within a subfolder called 'extensions' like such:

/application/libraries/extensions/MY_Form_validation.php

When trying the above the extended library is ignored and the default Form_validation class is loaded. Once this happened my first thought was to modify the subclass_prefix within /application/config/config.php to include the 'extensions' directory, however this resulted in an error stating:

Non-existent class: Form_validation

Is it possible to organize your extended libraries in this fashion within codeigniter? Does anyone know how it is done?


Solution

  • If It's have a sub-folder

    $this->load->library('extensions/MY_Form_validation');
    

    and after you can access like..

    $this->MY_Form_validation->your_function_name();