Setting global variables not working

So I need to pass some data thru an variable but I cant get it to work.

I have a view file where I want to define a value, and I have a controller file where I need this value.

When I define the value in the config file it will work, but as this value is dynamic I cannot set it in the config file.


main.php


Yii::$app->params['somevalue'] = 'hello world';




sitecontroller.php


echo Yii::$app->params['somevalue']; //not outputing any value



i think, your value replaced by configuration, like this




// main.php


$params = array_merge(

    require(__DIR__ . '/../../common/config/params.php'),

    require(__DIR__ . '/../../common/config/params-local.php'),

    require(__DIR__ . '/params.php'),

    require(__DIR__ . '/params-local.php')

);


return [

  .

  .

  .

  'params' => $params,

  .

  .

  .

];




You can set params value on params.php file

Because controller code executes earlier than view code.

Use <form> inputs.