How to set a flash message in Yii2? -


i followed link. code follows in controller

public function actionfunction4()     {         $this->layout="sintel";         $model= new customers();         \yii::$app->getsession()->setflash('success', 'successfully got on payment page');         return $this->render("function4",['model'=>$model]);     } 

in view

 <div id="message">            <?= yii::$app->session->getflash('success');?>       </div> 

now result of did not expected. got message "successfully got on payment page" have echo ed it. if similar echo why need flash message in yii2. think may missing in code make flash message appear regular one.

add below code in controller file like:

yii::$app->session->setflash('success', "your message display"); 

and add below code in view file like:

<?php if (yii::$app->session->hasflash('success')): ?>   <div class="alert alert-success alert-dismissable">   <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>   <h4><i class="icon fa fa-check"></i>saved!</h4>   <?= yii::$app->session->getflash('success') ?>   </div> <?php endif; ?> 

Comments