where to define constants in cakephp
In which file should I define开发者_Go百科 application-wide constants that are specific to my cakephp app?
I define them in app/config/bootstrap.php
Bootstrapping CakePHP
If you have any additional configuration needs, use CakePHP’s bootstrap file, found in app/Config/bootstrap.php. This file is executed just after CakePHP’s core bootstrapping.
This file is ideal for a number of common bootstrapping tasks:
- Defining convenience functions.
- Registering global constants.
- Defining additional model, view, and controller paths.
- Creating cache configurations.
- Configuring inflections.
- Loading configuration files.
Complete manual goes here
@travis:
i think its better to use the configs file (and configure class) for such dev/staging stuff
the bootstrap is more like the "general" more hardcoded stuff - all app configs together the configs are the "variant" config arrays.
just my 5 cents.
There is a another way to set constants in external file except doing it in long files like bootstrap (When it's doesn't effect on Behaviors like editable Pdf constants).
It could be retrieved from view, controller or model:
Configure::load('PDF_CONSTANT_FILE');
echo THE_CONSTANT;
// PDF_CONSTANT_FILE set in app/config/PDF_CONSTANT_FILE.php
Adding $config=array(); to PDF_CONSTANT_FILE.php file at start is necessary.
Just for general benefit.
精彩评论