php - how I use flash message in yii2? -
how add flash message site using related controller please explain step step i'm new php.
i use yii2 framework build site , need print flash message in index page using create controller.
currently question broad, here basic usage:
1) can set in controller that:
\yii::$app->session->setflash('flashmessage', 'hello world!');
2) can display in view so:
echo \yii::$app->session->getflash('flashmessage');
optionally can check existence with:
\yii::$app->session->hasflash('flashmessage');
official docs:
there more methods working flashes, can see in official docs.
also advanced template provides useful widget alert integrated boostrap 3:
\yii::$app->session->setflash('error', 'this error message'); ... echo alert::widget();
Comments
Post a Comment