1 /*application: For example, submit a form and submit a message on the page after the submission is complete. 2 inside the controller, write this:3 Single message:4 */5\yii::$app->getsession ()->setflash (' Error ', ' This is the message ');6 7\yii::$app->getsession ()->setflash (' Success ', ' This is the message ');8 9\yii::$app->getsession ()->setflash (' info ', ' This is the message ');Ten #more than one message: One\yii::$app->getsession ()->setflash (' Error ', [' Error 1 ', ' ERROR 2 ']); A - #Then there is the view: - theFirst, alert is introduced: UseYii\bootstrap\alert; - if(Yii::$app->getsession ()->hasflash (' success ')) ) { - EchoAlert::Widget ([ -' Options ' = [ +' Class ' = ' alert-success ',//here is the class of the Cue box -], +' Body ' = Yii::$app->getsession ()->getflash (' Success '),//message body A ]); at } - if(Yii::$app->getsession ()->hasflash (' ERROR ')) ) { - EchoAlert::Widget ([ -' Options ' = [ -' Class ' = ' Alert-error ', -], in' Body ' = Yii::$app->getsession ()->getflash (' Error '), - ]); to}
Project code Example:
1 //c controller Inside this write Companyinfocontroller2 //Company Information3 Public functionActionindex ()4 {5 $result= Companyservice::CompanyInfo ();6 $types= Yii::$app->params[' Companytype '];7 $model= Companyinfo::find ()->where ([' ID ' =>yii::$app->company->getid ()])One ();8 9 if(Yii::$app->request->post () && companyservice::updateconpanyinfo (Yii::$app->request->post ())) {TenYII::$app->session->setflash (' flag ', ' success '); One A return $this->redirect ('/system/company-info/index '); - } - return $this->render (' Index ', [ the' Staffnum ' =$result[' Staffnum '], -' Model ' =$model, -' type ' = =$types, -' Businesslist ' =$result[' Businesslist '], +' Businessparentid ' =$result[' Businessparentid '], -' Sonbusinesslist ' =$result[' Sonbusinesslist '] + ]); A } at - //View inside index.php -<script type= "Text/javascript" > - //message prompt Start -<?php$flag= Yii::$app->session->getflash (' flag ');if($flag= = ' success '):?> - inLayer.msg (' Company Information updated successfully '); - to<?phpendif;?> + //Message Tip End - the *</script>
YII set Flash message to create a fading form message box