I can not yet get used to the documentation (well, and / or with the logic of the work of Yii2).

Suppose I want to add a CSS class to the ActiveFrom form. This is done like this:

 ActiveForm::begin([ 'method' => 'get', 'options' => [ 'class' => 'my-css-class' ] ]); 

I can not find where it is described in the documentation, in particular, about options : what are they for and why it is there that you need to put the CSS class, and not by analogy with other attributes that are not transferred to options .

I went to the ActiveForm page, from there to the begin () method, which is inherited from yii\base\Widget ; it says that the method accepts an array of configuration:

 public static static begin ( $config = [] ) 
  • $ config | array | Name-value pairs
  • return - static - The newly created widget instance

Where exactly should I look for information on handling name-value pairs?

    1 answer 1

    In this case, everything is simple, the begin () method creates an instance of the widget class using Yii :: createObject () , which, in turn, uses the dependency injection container .

    As a result, the values ​​of the elements of the array passed to the begin () method are assigned to the corresponding properties of the new object. On your code, this is method and options .

    The properties of the widget are described in sufficient detail in the documentation ($ options - The HTML attributes (name-value pairs) for the form tag).

    In other words, in the array passed to begin (), you set the values ​​of the widget properties.