Creating reusable controllers
In Yii, you can create reusable controllers. If you are creating a lot of applications or controllers that are of the same type, moving all common code into a reusable controller will save you a lot of time.
In this recipe, we try to create a common
CleanController, which will clear temporary directories and flush cached data.
Create a new
yii2-app-basic application using the composer as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
How to do it…
Carry out the following steps to create reusable controllers:
- Create the
cleanerdirectory and add the standalone
<?php namespace app\cleaner; use Yii; use yii\filters\VerbFilter; use ...