I want themming my frontend advanced app. The users choice will be saved in database, i try with Bundle assets but i don’t have success, the bootstrap is executed after AppAsset. How i should do it?
frontend/assets:
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/checkbox.css',
'//maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
public $skin = 'default';
public function init()
{
if ($this->skin) {
if (('default' !== $this->skin) && (strpos($this->skin, 'skin-') !== 0)) {
throw new Exception('Invalid skin specified');
}
$this->css[] = sprintf('css/skins/%s.css', $this->skin);
}
parent::init();
}
}
<?php
namespace frontend\assets;
use Yii;
use yii\base\BootstrapInterface;
class AppAssetBootstrap implements BootstrapInterface
{
public function init()
{
parent::init();
}
public function bootstrap($app)
{
$bundle = $app->assetManager->getBundle('frontend\assets\AppAsset');
$bundle->skin = 'skin-blue';
try{
} catch(yii\db\Exception $e){
return false;
}
}
}
frontend/config/main.php
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => [
'log',
'frontend\assets\AppAssetBootstrap'
],
'controllerNamespace' => 'frontend\controllers',
'language' => 'pt-BR',
'components' => [
'request' => [
'enableCookieValidation' => true,
'enableCsrfValidation' => true,
'cookieValidationKey' => 'k6@/oe0-9w*>=]OM?wa19F%6qA^:8Y',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => true,
'enableStrictParsing' => false,
'rules' => [
],
]
],
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module'
]
],
'params' => $params,
];