开发者

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:

  1. Defining convenience functions.
  2. Registering global constants.
  3. Defining additional model, view, and controller paths.
  4. Creating cache configurations.
  5. Configuring inflections.
  6. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜