Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Yii2: Config params vs. const/define

$
0
0

When should I use what?

I have the option to define constants in the index.php entry script file like it is recommended in Yii2 guide: constants. Or I could use the params in the configuration - explained in YII2 guide: params. Both are per application and not really global.

Currently, it seems to me that params are a bit less comfortable if I want to combine values like this:

define('SOME_URL',            'http://some.url');define('SOME_SPECIALIZED_URL', SOME_URL . '/specialized');

Besides, accessing is bit more code (Yii::$app->params['something']) compared to constants.

So when should or could I use what?

Small update: in PHP 7 define() supports arrays as well, so the whole params structure can be configured as a constant. Probably better supported by IDEs.


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>