here so I use in representation

use frontend\widget\wath\Wath; <?= Wath::widget(['serial'=>$model,'theSerial'=>0,'class'=>'film']); ?> 

like this in Wath.php

 class Wath extends Widget { public $serial; public $theSerial; public $class; public function init() { parent::init(); } public function run() { return var_dump($this->class); } } 

gives null, but if $this->serial then it gives what comes 'serial'=>$model

    1 answer 1

    Just reading the configuration documentation and there it is indicated regarding widgets:

    The configuration array should NOT have the class key.

    Source

    Or in our opinion:

    Note that the class parameter is NOT passed because the full name is already specified.

    A source


    In general, the configuration in Yii2 is an array of the following form:

     [ 'class' => 'ClassName', 'propertyName' => 'propertyValue', 'on eventName' => $eventHandler, 'as behaviorName' => $behaviorConfig, ] 

    Source

    In cases of application and widget configuration, the class property is not specified, since the class name has already been obtained ...

    For the application in the incoming script:

     (new yii\web\Application($config))->run(); 

    For a widget (specifically for a Menu widget):

     use yii\widgets\Menu; echo Menu::widget([ 'activateItems' => false, 'items' => [ ['label' => 'Home', 'url' => ['site/index']], ['label' => 'Products', 'url' => ['product/index']], ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest], ], ]); 

    In other words, the class property is reserved for internal use by Yii2: to specify the class whose instance we want to create, configure, and use for something.