Using flash messages
When you are editing a model with a form, deleting a model, or doing any other operation, it is good to tell users if it went well or if there was an error. Typically, after some kind of action, such as editing a form, a redirect will happen and we need to display a message on the page we want to go to. However, how do we pass it from the current page to the redirect target and clean up afterwards? Flash messages will help us do this.
Getting ready
Create a new application using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
How to do it…
Let's create a
@app/controllers/TestController.php
controller as follows:<?php namespace app\controllers; use Yii; use yii\web\Controller; use yii\filters\AccessControl; class TestController extends Controller { public function behaviors() { return [ 'access' => [ 'class' => AccessControl::className...