Code Igniter User Guide Version 1.4.0


The Scripts Folder

Inside the application directory you'll find a folder called scripts. Its purpose is to give you a place to store your own script includes or classes.

Loading a Script

Your scripts can be loaded in your controllers or views using the following function:

$this->load->script('name');

Where name is the file name of the script, without the .php file extension.

For example, to load a file called utilities.php you would do this:

$this->load->script('utilities');

If you load a script in your controller constructor it will be available automatically in any function, or you can load it in a specific function that needs it.

Note: The Script loading function above does not return a value, so don't try to assign it to a variable. Just use it as shown.

Loading Multiple Scripts

If you need to load more than one script you can specify them in an array, like this:

$this->load->script( array('script1', 'script2', 'script3') );

Auto-loading Scripts

If you find that you need a particular script globally throughout your application, you can tell Code Igniter to auto-load it during system initialization. This is done by opening the application/config/autoload.php file and adding the script to the autoload array.