Yii2 bouton onclick fonction anonyme

Je suis nouveau sur Yii2, et j'ai du mal à déclencher une fonction anonyme en appuyant sur un Yii2 bouton.
Ci-dessous sont de 6 échantillons, dont les deux premières sont OK.
Mais ce n'est pas exactement ce que je souhaite avoir.
Je voudrais savoir comment je peux obtenir une fonction anonyme de travail, comme des cas de "Bouton 3" et "Bouton 5". J'ai testé comment faire un appel de fonction via le Contrôleur, et qui fonctionne ok, mais c'est ni ce que je veux. Je vous serais reconnaissant de Votre aide, merci!

//This works
$button1 = Button::begin ( 
[
'label' => 'Button 1',
'options' => [
    'class' => 'btn btn-primary',
    'onclick' => 'alert("Button 1 clicked");',
    ],
]);
$button1->run();

//This works
echo Html::button('Button 2', [ 'class' => 'btn btn-primary', 'onclick' => 'alert("Button 2 clicked");' ]);

//This DOES NOT work
echo Html::button('Button 3', [ 'class' => 'btn btn-primary', 'onclick' => 'function ( $event ) { alert("Button 3 clicked"); }' ]);

//This DOES NOT work
$button4 = Button::begin ( 
[
'label' => 'Button 4',
'options' => [
    'class' => 'btn btn-primary',
    //'onclick' => 'alert("Button 1 clicked");',
    ],
]);
$button4->on('onclick', 'alert("Button 4 clicked");' );
$button4->run();


//This DOES NOT work
$button5 = Button::begin ( 
[
'label' => 'Button 5',
'options' => [
    'class' => 'btn btn-primary',
    'onclick' => 'function ( $event ) { alert("Button 5 clicked"); }',
    ],
]);
$button5->run();

//This DOES NOT work
$button6 = Button::begin ( 
[
'label' => 'Button 6',
'options' => [
    'class' => 'btn btn-primary',
    //'onclick' => 'function ( $event ) { alert("Button 4 clicked"); }',
    ],
]);
$button6->on('onclick', 'function ( $event ) { alert("Button 6 clicked"); }' );
$button6->run();