Answer the question
In order to leave comments, you need to log in
Is it possible to declare parameters in yii2 so that all controllers receive it?
How to declare parameters so that all controllers receive them. The fact is that I have several organizations in the project,
and each time I write
User::findOne(Yii::$app->user->id)->organization->id
Answer the question
In order to leave comments, you need to log in
Dumb idea overall no need for this functionality.
Well, you take Yuiya's base controller, inherit from it, get your base controller, override the constructor and write this line in it and save the result in a protected field (or in a private one with a getter).
You inherit the rest of your controllers from your received
first option: Yii::$app->user->identity->organization->id
Add to the User class (which is ActiveRecord) an association with hasOne (or hasMany) and associate it with the organization table
As far as I understand, you have already implemented this, simply try the
second option.
Add as a global variable i.e. Yii::$app->organization->id
Third option
explained here :
add as parameter
Yii::$app->params['organization_id'];
to do this, in the application config, add the column
'params' => [
'organization_id' => User::findOne(Yii::$app->user->id)->organization->id,
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question