'view' => [
'theme' => [
'pathMap' => ['@app/views' => '@app/themes/mythemes'],
'baseUrl' => '@web/themes/mythemes',
'basePath' => '@app/themes/mythemes',
],
],
<link href="<?php echo $this->theme->baseUrl ?>/css/style.css" rel="stylesheet" media="screen" title="default">
assets/AppAsset.php
'components' => [
'view' => [
'theme' => [
'pathMap' => ['@app/views' => '@app/themes/mytheme'],
],
],
],
class AppAsset extends AssetBundle
{
public $sourcePath = '@app/themes/mytheme';
public $css = [
'css/style.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
<?php
namespace app\components;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\FileHelper;
class Theme extends \yii\base\Theme
{
public $active;
/**
* @inheritdoc
*/
public function applyTo($path)
{
$pathMap = ArrayHelper::getValue($this->pathMap,$this->active,$this->pathMap);
if (empty($pathMap)) {
if (($basePath = $this->getBasePath()) === null) {
throw new InvalidConfigException('The "basePath" property must be set.');
}
$pathMap = [Yii::$app->getBasePath() => [$basePath]];
}
$path = FileHelper::normalizePath($path);
foreach ($pathMap as $from => $tos) {
$from = FileHelper::normalizePath(Yii::getAlias($from)) . DIRECTORY_SEPARATOR;
if (strpos($path, $from) === 0) {
$n = strlen($from);
foreach ((array) $tos as $to) {
$to = FileHelper::normalizePath(Yii::getAlias($to)) . DIRECTORY_SEPARATOR;
$file = $to . substr($path, $n);
if (is_file($file)) {
return $file;
}
}
}
}
return $path;
}
}
'view'=>[
'theme' => [
'class'=>'app\components\Theme',
'active'=>'theme-default',
'pathMap' => [
'theme-default' => [
'@app/views' => ['@app/themes/theme-default/views']
],
'theme-dashboard' => [
'@app/views' => ['@app/themes/theme-dashboard/views']
]
]
],
],
$this->view->theme->active = 'theme-dashboard';
list($path, $webPath) = Yii::$app->getAssetManager()->publish(__DIR__."/assets");
$this->getView()->registerJsFile($webPath."/js/login.js",['depends' => ['yii\bootstrap\BootstrapAsset']]);