Bynd
Bynd

Reputation: 705

Yii2 Basic Globale variable and function

With Yii2 basic is it possible to create variables and function that I can use in all controllers and views; If it possible can help on how I try create it on : config/params.php

return [
    'adminEmail' => '[email protected]',
    'dafult-Img' => 'upload/user/'.Yii::$app->user->getId().'/',
];

but when I use it on controller

$model->userimage= Yii::$app()->params['dafult-Img'];

I get error

Undefined variable: app

Upvotes: 1

Views: 61

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

In yii2 you should use $app and not $app()

 Yii::$app->params['dafult-Img'];

could be you need a

Upvotes: 1

Related Questions