YII会话:Flash数据用法示例

Flash数据是一种会话数据, 具有以下功能。

  • 设置一个请求。
  • 仅在下一个请求期间可用。
  • 之后自动删除。

它主要用于向最终用户传递仅传递一次的消息, 例如登录后发送的确认消息。

例子

步骤1在SiteController.php文件中创建操作ationFlashData。

public function actionFlashData() 
    { 
   $session = Yii::$app->session; 
   // set a flash message named as "welcome" 
   $session->setFlash('welcome', 'Successfully Logged In!'); 
   return $this->render('flashdata'); 
    }

步骤2在views / site文件夹中创建一个视图文件flashdata.php。

<?php 
   use yii\bootstrap\Alert; 
   echo Alert::widget([ 
      'options' => ['class' => 'alert-info'], 'body' => Yii::$app->session->getFlash('welcome'), ]); 
?>

步骤3在带有URL的浏览器中运行它,

http://localhost/flash/frontend/web/index.php?r=site/flash-data
YII Flash数据1
微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_46585.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?