yii2 学习笔记 ---- Yii2页面提示消息

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41120504/article/details/88076842

单条消息: 

\Yii::$app->getSession()->setFlash('error', 'This is the message');

\Yii::$app->getSession()->setFlash('success', 'This is the message');

\Yii::$app->getSession()->setFlash('info', 'This is the message');

多条消息:

\Yii::$app->getSession()->setFlash('error', ['Error 1', 'Error 2']);

实例:

控制器:

Yii::$app->getSession()->setFlash('error', '跳转方式为跳转到网页(跳转链接或者是名称,根据link_type决定)只能填网址');

试图:

use yii\bootstrap\Alert;
    
    <?php
    if( Yii::$app->getSession()->hasFlash('error') ) {
        //如果想和js一样弹窗就用下面注释的代码
        //echo "<script>alert('" . Yii::$app->session->getFlash('error') . "')</script>";
        echo Alert::widget([
            'options' => [
                'class' => 'alert-error',
            ],
            'body' => Yii::$app->getSession()->getFlash('error'),
        ]);
    } ?>

效果图: 

猜你喜欢

转载自blog.csdn.net/weixin_41120504/article/details/88076842
今日推荐