Alert Should Be Executed Or Shown On Certain Condition

This code is written in controller say in ‘If’ block


Yii::$app->getSession()->setFlash('success', 'New Group is successfully created.');

Then to show Alert which code should I write in View.

I have tried below code with above code:




Alert::begin([

       'options' => [

                'class' => 'alert-warning',

       ],

]);

echo 'Say hello...';

Alert::end();



But It shows Alert on every new request, without 1st code execution on various condition.

Please Help.