How to use constant variables in Yii


Posted on 16 Apr 15 by Vickey

In Yii we can define our constant in /config/params.php file

return [
    'adminEmail'        => '',
    'application_name'  => 'My App',

and in our views an controller we can access these by using

Yii::app()->params['application_name'];  // in yii 1

Yii::$app->params['application_name']; // in yii 2

If this post help you reduce time to develop, you can help me to maintain this website :)