Skip to content
Jeff Johns edited this page Feb 12, 2014 · 26 revisions

Custom Directory

The custom directory is so that you can easily extend the base open source install of Nilai. You can easily overwrite models, controllers, routes, etc. All you need to do is mirror the directory and files you want to override from the /applications folder. The custom loader will check under /custom for the file first. If found, use that. If not move to /application folder.

Any config/route files will load both. Meaning if you redefine /custom/configs/routes.php, the loader will load the application version first and then your custom one. That way you can just overwrite or add what you need to configuration files and not have to redefine the entire file.

If you want controllers, models or libraries to extend application version just make it so. If you rather they extend the base CI_Controller you can do that too.

Routes

The core application has default routes. If you wish to change these routes or add new one you can by adding a routes.php file to your /custom/config folder. If you are using ENVIRONMENT folders in configs you can do that as well, IE: /custom/config/development/routes.php.

You don't need to redefine every route, just create your own routes file and add or update the routes you need. The core application's routes load first, then the custom routes. So you can keep the application routes, change a few of them, add new ones or a combination of all those.

Autoloading

Autoloading works just like routes except nothing in the default autoload file is overwritten. The application itself needs items to load automatically, if you custom app does, just create your own autoload file under /custom/config/autoload.php. You don't need to redefine anything in the core one, just add what you need. We will merge the two files at runtime.

Configs

Configs work the same way as routes. We load the core application's configs first then any custom ones. This way you can override, add or append other items to existing application configs. Let's say your application was adding a new error code. The core application has these defined in /application/config/all/app.php. You want to add error code 702 for Random error. Simply create custom/config/all/app.php and add $config['error_codes'][702] = 'Random Error' and it will be appended to the existing error codes.

It knows if it should append or overwrite a config. If you need to load any custom configs just for your application please add them to your autoload file.

Helpers, Libraries, Controllers and Models

You can redefine any of the core application's files just by placing them in the same folder structure and file name in your custom folder. If you do this for any of the above it will be loaded instead of the application's. This way when we update the core application you don't end up with bunch of merge conflicts.

Helpers

Place any helpers in /custom/helpers/{NAME}_helper.php.

Libraries

Place any libraries in /custom/libraries/{LIBRARY}.php.

Models

Place any models in /custom/models/{MODEL}.php.

Controllers

Place any controllers in /custom/controllers/{controller}.php.

Remember

If you are loading any custom files, that you need to load them either in your custom application or in the autoload file. For custom controllers, you will need to add a route when applicable.

Security

It's wise on your part to add any level of security you wish. Below are a few methods:

PHP

Add this to the top of every file in the custom directory.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

.htaccess

Deny from all

nginx

location ~* ^/(custom) {
    deny all;
}
Clone this wiki locally