PHP code example of mbrowniebytes / yii2-clean-assets

1. Go to this page and download the library: Download mbrowniebytes/yii2-clean-assets library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mbrowniebytes / yii2-clean-assets example snippets


'controllerMap' => [
    'clean-assets' => [
        'class' => 'mbrowniebytes\yii2cleanassets\CleanAssetsController',
    ],
],


namespace app\controllers;

use Yii;
use yii\web\Controller;
use app\commands\CleanAssetsController as CleanAssets;

class BaseController extends Controller
{
	private function cleanAssets()
	{
		// keep dev/test env clean; remove old web/assets/ caches
		if (YII_ENV != 'prod' && rand(0, 100) < 30) {
			$clean_assets = new CleanAssets('CleanAssetsController', 'command');
			$clean_assets->keep = 4;
			$clean_assets->silent = true;
			$nbr_cleanded = $clean_assets->cleanAssetDirs();
		}
	}

	public function afterAction($action, $result)
	{
		$this->cleanAssets();
		
		return parent::afterAction($action, $result);
	}
}


namespace app\controllers;

use Yii;
use yii\web\Controller;

class MyController extends BaseController
{
    public function actionIndex()
    {
    }
}