In the yii2-advanced-app, the jui assets are found in paths like: web\assets\135efca3\
in which themes
and ui
folders are found -Indeed, I don't know why Yii2 makes a varied path segment or fake path-. I think that getAssetPath() method of assetManager should return that path, but I don't know how!
I tried the following debugging code in the actions()
method of the controller:
public function actions()
{
echo Yii::$app->assetManager->getAssetPath(Yii::$app->assetManager->bundles = [
'yii\jui\JuiAsset'], 'themes');
die(); //for debugging
}
However, it just prints /themes
.
In other words, I can ask, how could I able to supply the first parameter (object) of getAssetPath()
? because, I think it is the problem here.
Edit
I have created the following helper -according to arogachev answer about the path- to get a list of themes.
<?php
namespace common\libs;
use yii;
use yii\web\Controller;
class JuithemeHelpers
{
public static function getThemesList()
{
$themesPath = dirname(Yii::$app->basePath).DIRECTORY_SEPARATOR."vendor".DIRECTORY_SEPARATOR."bower".DIRECTORY_SEPARATOR."jquery-ui".DIRECTORY_SEPARATOR."themes";
$output = [];
foreach (scandir($themesPath) as $item){
if (is_dir($themesPath.DIRECTORY_SEPARATOR.$item) && ($item != '.' && $item !='..')) $output[] = $item;
}
return $output;
}
}
Then in the view I have made the following:
...
<?= $form->field($model, 'birthdate')->widget(DatePicker::className(), ['clientOptions' => ['dateFormat' => 'yy-mm-dd', 'changeYear' => true, 'yearRange' => sprintf('%s:%s', date('Y')-100,date('Y')-16)],]) ?>
<select onchange="changeTheme(this.value)">
<?php foreach (JuithemeHelpers::getThemesList() as $item): ?>
<option value="<?= $item ?>"><?= $item ?></option>
<?php endforeach; ?>
</select>
<?= $form->field($model, 'gender_id')->dropDownList($model->getGenderList(), ['prompt' => 'Please Select one...']) ?>
...
......
<script>
function changeTheme(n){
s = document.getElementsByTagName('link');
o = ''
re = /\/themes\/(.*)\/jquery-ui.css/gi;
for (i = 0; i < s.length; i++){
if (s[i].href.match(re)){
o = s[i].href.replace(re.exec(s[i].href)[1],n);
s[i].href=o;
}
}
}
</script>
I think that now is the time to learn how to package all of this in a widget.