where to define constants in cakephp

后端 未结 3 1983
故里飘歌
故里飘歌 2021-02-07 09:14

In which file should I define application-wide constants that are specific to my cakephp app?

相关标签:
3条回答
  • 2021-02-07 09:28

    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 讨论(0)
  • 2021-02-07 09:50

    @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.

    0 讨论(0)
  • 2021-02-07 09:52

    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

    0 讨论(0)
提交回复
热议问题