There are two widgets (example from docks)
The first
namespace app\components; use yii\base\Widget; use yii\helpers\Html; class HelloWidget extends Widget { public $message; public function init() { parent::init(); if ($this->message === null) { $this->message = 'Hello World'; } } public function run() { return Html::encode($this->message); } } And the second
namespace app\components; use yii\base\Widget; use yii\helpers\Html; class WorldWidget extends Widget { public function init() { parent::init(); } public function run() { $this->message // получить переменную виджета HelloWidget } } Widgets are called one after another in one view, i.e.
HelloWidget::widget(['message' => 'Good morning']) WorldWidget::widget() Is it possible to get the value of the $ message variable of the HelloWidget widget in the WorldWidget widget? Try so
\Yii::$app->view->message I get
Getting unknown property: yii \ web \ View :: message