Tuesday, January 4, 2011

Some CodeIgniter Constants

As a CI dev I am sure you have seen these before, and they are pretty useful once defined. The problem is that the CI docs don't really tell you what they are, and their names are only descriptive once you know what they do. To the new guy these may seem to have some kind of mystical powers.

Here is a link to the docs that outlines the constants listed below.
http://codeigniter.com/user_guide/general/reserved_names.html

The first constant is APPPATH (thats 3 'P's ). This variable is initialized in the root index.php file and is the path to the application folder of your CI installation. Pretty straight forward.

BASEPATH is the path to the system folder of you CI application. This is defined in the root index.php file.

CI_VERSION as I am sure it is obvious, is the version of CodeIgniter you are running.

DIR_READ_MODE, DIR_WRITE_MODE these values are used when dealing with files in CI. Namely when checking and setting read write modes of directories. These values reside in the constants config file of CI.


EXT refers to a file extension which would typically be ".php". This is defined in the root index.php file.

FCPATH is the full server path to the root index.php file. This is defined in the root index.php file.
FILE_READ_MODE, FILE_WRITE_MODE same as DIR_READ_MODE, DIR_WRITE_MODE except these deal with files instead of directories.

Next are a bunch of FOPEN constants which as the name implies deal with using fopen and popen in CI. These also reside in the constants config file if you want to take a peak at them.

SELF refers to the name of the root index.php file and usually has a value of "index.php". This is defined in the root index.php file.

Really the only constants that would be used with any kind of regularity are APPPATH and BASEPATH. The others are more involved in the internals of CI, but I am sure they are useful in some circumstances.

Hopefully that gives you a better idea of what these suckers do.

No comments:

Post a Comment