YII set Flash message to create a fading form message box

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.