Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Should I define global constants in index.php or in fuel/app/bootstrap.php?
  • Hi guys!

    I would like to get a value of URL media files and media my directory. Currently I have putting this settings in app/config/config.php. However, I intend to define constants (MEDIA_URL, MEDIA_ROOT) on index.php, such as APPROOT, COREPATH... 

    So here is go my question: Is it safe to do it? Is there some downside for future upgrades/updates?

    Thanks in advance!
  • philipptempelphilipptempel
    Accepted Answer
    Out of these two options, you should define them in the file APPPATH/bootstrap.php. They shouldn't go into the DOCROOT/index.php because that is a place to only get your app going and should be kept easily upgradable which can only be obtained by not really touching the file.

    However, the best is probably to define an app-sepcific file at config/app.php which does not keep these constants but keeps them in the array e.g.


    <?php

    return array(
        'media_url' => DOCROOT . 'media',
    );

    /* end of file app/config/app.php */



    This config file should then be auto-loaded in the app/config.php:always_load.config

    Using this approach you can update fuel without problems and all your app-specific data is defined in the app's config files (from my point of view those constants you want to define shouldn't be DEFINE'd constants but rather static config variables.)
  • We do exactly the same.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion