本文整理汇总了PHP中yii\helpers\Html::activeListBox方法的典型用法代码示例。如果您正苦于以下问题:PHP Html::activeListBox方法的具体用法?PHP Html::activeListBox怎么用?PHP Html::activeListBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Html
的用法示例。
在下文中一共展示了Html::activeListBox方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @inheritdoc
*/
public function run()
{
$inputId = $this->options['id'];
$hasModel = $this->hasModel();
if (array_key_exists('value', $this->options)) {
$value = $this->options['value'];
} elseif ($hasModel) {
$value = Html::getAttributeValue($this->model, $this->attribute);
} else {
$value = $this->value;
}
$options = array_merge($this->options, ['multiple' => true, 'value' => $value]);
if ($hasModel) {
$output = Html::activeListBox($this->model, $this->attribute, $this->items, $options);
} else {
$output = Html::listBox($this->name, $this->value, $this->items, $options);
}
$clientOptions = array_merge(['filter' => $this->filter, 'multiple' => $this->multiple, 'multipleWidth' => $this->multipleWidth], $this->clientOptions);
if (!array_key_exists('placeholder', $clientOptions) && array_key_exists('placeholder', $options)) {
$clientOptions['placeholder'] = $options['placeholder'];
}
$js = 'jQuery(\'#' . $inputId . '\').multipleSelect(' . Json::htmlEncode($clientOptions) . ');';
if (Yii::$app->getRequest()->getIsAjax()) {
$output .= Html::script($js);
} else {
$view = $this->getView();
MultipleSelectAsset::register($view);
$view->registerJs($js);
}
return $output;
}
示例2: run
/**
* @inheritdoc
*/
public function run()
{
try {
$this->_initAndValidate();
$valueArray = [];
$trees = [];
$valueSingle = "";
$select = "";
$singleInput = "";
if (in_array($this->mode, [self::MOD_COMBO, self::MOD_MULTI])) {
$valueArray = Html::getAttributeValue($this->model, $this->attribute);
$select = Html::activeListBox($this->model, $this->attribute, ['16' => "16"], ['multiple' => true, 'class' => 'sx-controll-element', 'style' => 'display: none;']);
$trees = Tree::find()->where(['id' => $valueArray])->all();
}
if (in_array($this->mode, [self::MOD_COMBO, self::MOD_SINGLE])) {
$singleInput = Html::activeInput("hidden", $this->model, $this->attributeSingle, ['class' => 'sx-single']);
$valueSingle = Html::getAttributeValue($this->model, $this->attributeSingle);
}
$src = UrlHelper::construct('/cms/admin-tree')->set('mode', $this->mode)->set('s', $valueArray)->setSystemParam(Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->setSystemParam(Module::SYSTEM_QUERY_NO_ACTIONS_MODEL, 'true')->enableAdmin()->toString();
$id = "sx-id-" . md5(serialize([$this->clientOptions, $this->mode, $this->attributeMulti, $this->attributeSingle]));
$selected = [];
foreach ($trees as $tree) {
$selected[] = $tree->id;
}
return $this->render('widget', ['widget' => $this, 'id' => $id, 'select' => $select, 'src' => $src, 'valueSingle' => $valueSingle, 'singleInput' => $singleInput, 'clientOptions' => Json::encode(['src' => $src, 'name' => $id, 'id' => $id, 'selected' => $selected, 'valueSingle' => $valueSingle])]);
//$this->registerClientScript();
} catch (Exception $e) {
echo $e->getMessage();
}
}
示例3: run
/**
* @inheritdoc
* @throw NotSupportedException
*/
public function run()
{
if ($this->hasModel()) {
if (!is_null($this->value)) {
if (!in_array($this->attribute, $this->model->attributes())) {
throw new NotSupportedException('Unable to set value of the property \'' . $this->attribute . '\'.');
}
$stash = $this->model->{$this->attribute};
$this->model->{$this->attribute} = $this->value;
}
$output = Html::activeListBox($this->model, $this->attribute, $this->items, $this->options);
if (isset($stash)) {
$this->model->{$this->attribute} = $stash;
}
} else {
$output = Html::listBox($this->name, $this->value, $this->items, $this->options);
}
$js = 'jQuery(\'#' . $this->options['id'] . '\').select2(' . Json::htmlEncode($this->clientOptions) . ');';
if (Yii::$app->getRequest()->getIsAjax()) {
$output .= Html::script($js);
} else {
$view = $this->getView();
Select2Asset::register($view);
Select2LanguageAsset::register($view);
$view->registerJs($js);
}
return $output;
}
示例4: run
/**
* @inheritdoc
*/
public function run()
{
$value = $this->model->{$this->attribute};
$items = $value;
if ($value && is_string($value) || is_int($value)) {
$items = [$value => $value];
}
if (!$items) {
$items = [];
}
$this->options['multiple'] = $this->multiple;
Html::addCssClass($this->options, 'sx-widget-element');
$select = Html::activeListBox($this->model, $this->attribute, $items, $this->options);
$this->clientOptions['value'] = $value;
$this->clientOptions['multiple'] = (int) $this->multiple;
$this->registerAssets();
return $this->render('select-tree-widget', ['elementForm' => $select]);
}
示例5: run
/**
* @inheritdoc
*/
public function run()
{
if ($this->hasModel()) {
echo Html::hiddenInput(Html::getInputName($this->model, $this->attribute));
//TODO:bad hardcode
echo Html::activeListBox($this->model, $this->attribute, $this->items, $this->options);
} else {
echo Html::hiddenInput($this->name);
//TODO:bad hardcode
echo Html::listBox($this->name, $this->value, $this->items, $this->options);
}
}
示例6: listBox
/**
* Renders a list box.
* The selection of the list box is taken from the value of the model attribute.
* @param array $items the option data items. The array keys are option values, and the array values
* are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too).
* For each sub-array, an option group will be generated whose label is the key associated with the sub-array.
* If you have a list of data models, you may convert them into the format described above using
* [[\yii\helpers\ArrayHelper::map()]].
*
* Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in
* the labels will also be HTML-encoded.
* @param array $options the tag options in terms of name-value pairs. The following options are specially handled:
*
* - prompt: string, a prompt text to be displayed as the first option;
* - options: array, the attributes for the select option tags. The array keys must be valid option values,
* and the array values are the extra attributes for the corresponding option tags. For example,
*
* ~~~
* [
* 'value1' => ['disabled' => true],
* 'value2' => ['label' => 'value 2'],
* ];
* ~~~
*
* - groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options',
* except that the array keys represent the optgroup labels specified in $items.
* - unselect: string, the value that will be submitted when no option is selected.
* When this attribute is set, a hidden field will be generated so that if no option is selected in multiple
* mode, we can still obtain the posted unselect value.
*
* The rest of the options will be rendered as the attributes of the resulting tag. The values will
* be HTML-encoded using [[Html::encode()]]. If a value is null, the corresponding attribute will not be rendered.
*
* @return static the field object itself
*/
public function listBox($items, $options = [])
{
$options = array_merge($this->inputOptions, $options);
$this->adjustLabelFor($options);
$this->parts['{input}'] = Html::activeListBox($this->model, $this->attribute, $items, $options);
return $this;
}
示例7: run
/**
* @inheritdoc
*/
public function run()
{
if ($this->hasModel()) {
echo Html::activeListBox($this->model, $this->attribute, $this->items, $this->options);
} else {
echo Html::listBox($this->name, $this->value, $this->items, $this->options);
}
}
示例8: run
/**
* @inheritdoc
*/
public function run()
{
echo "<div class='row'>";
echo "<div class='col-md-6'>";
if ($this->hasModel()) {
echo Html::activeListBox($this->model, $this->attribute, $this->items, $this->options);
} else {
echo Html::listBox($this->name, $this->value, $this->items, $this->options);
}
echo "</div>";
echo "<div class='col-md-6'>";
$createUrl = (string) \skeeks\cms\helpers\UrlHelper::construct($this->controllerRoute . '/' . $this->createAction)->setSystemParam(\skeeks\cms\modules\admin\Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->setSystemParam(\skeeks\cms\modules\admin\Module::SYSTEM_QUERY_NO_ACTIONS_MODEL, 'true')->enableAdmin()->toString();
$updateUrl = (string) \skeeks\cms\helpers\UrlHelper::construct($this->controllerRoute . '/' . $this->updateAction)->setSystemParam(\skeeks\cms\modules\admin\Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->setSystemParam(\skeeks\cms\modules\admin\Module::SYSTEM_QUERY_NO_ACTIONS_MODEL, 'true')->enableAdmin()->toString();
$create_w = \Yii::t('app', 'Create');
$edit_w = \Yii::t('app', 'Edit');
echo <<<HTML
<a href="{$createUrl}" class="btn btn-default sx-btn-create sx-btn-controll" ><span class="glyphicon glyphicon-plus"></span> {$create_w}</a>
<a href="{$updateUrl}" class="btn btn-default sx-btn-update sx-btn-controll" ><span class="glyphicon glyphicon-pencil"></span> {$edit_w}</a>
HTML;
echo "</div>";
echo "</div>";
Pjax::end();
$options = ['multiple' => (int) $this->multiple];
$optionsString = Json::encode($options);
$this->view->registerJs(<<<JS
(function(sx, \$, _)
{
sx.classes.FormElementEditedSelect = sx.classes.Widget.extend({
_init: function()
{},
getWrapper: function()
{
return \$(this._wrapper);
},
_onDomReady: function()
{
var self = this;
\$(this.getWrapper()).on('change', 'select', function()
{
self.updateButtons();
});
\$(this.getWrapper()).on('click', '.sx-btn-create', function()
{
var windowWidget = new sx.classes.Window(\$(this).attr('href'));
windowWidget.bind('close', function(e, data)
{
self.reload();
});
windowWidget.open();
return false;
});
\$(this.getWrapper()).on('click', '.sx-btn-update', function()
{
var windowWidget = new sx.classes.Window(\$(this).attr('href') + '&pk=' + \$('select', self.getWrapper()).val());
windowWidget.bind('close', function(e, data)
{
self.reload();
});
windowWidget.open();
return false;
});
self.updateButtons();
},
_onWindowReady: function()
{},
updateButtons: function()
{
var self = this;
if (!self.get('multiple'))
{
if (\$('select', this.getWrapper()).val())
{
self.showUpdateControll();
} else
{
self.hideUpdateControll();
}
} else
{
self.hideUpdateControll();
//.........这里部分代码省略.........
示例9: function
$searchRelatedPropertiesModel->load(\Yii::$app->request->get());
if ($dataProvider)
{
$searchRelatedPropertiesModel->search($dataProvider, $user->tableName());
}
if ($user->relatedPropertiesModel)
{
$autoColumns = \skeeks\cms\modules\admin\widgets\GridViewStandart::getColumnsByRelatedPropertiesModel($user->relatedPropertiesModel, $searchRelatedPropertiesModel);
}
?>
<?php
echo $this->render('_search', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
?>
<?php
echo \skeeks\cms\modules\admin\widgets\GridViewStandart::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'adminController' => $controller, 'pjax' => $pjax, 'columns' => \yii\helpers\ArrayHelper::merge([['class' => \skeeks\cms\grid\ImageColumn2::className(), 'attribute' => 'image_id', 'relationName' => 'image'], 'username', 'name', 'email', ['class' => \skeeks\cms\grid\BooleanColumn::className(), 'attribute' => "email_is_approved", 'trueValue' => 1, 'falseValue' => 0], 'phone', ['class' => \skeeks\cms\grid\BooleanColumn::className(), 'attribute' => "phone_is_approved", 'trueValue' => 1, 'falseValue' => 0], ['class' => \skeeks\cms\grid\CreatedAtColumn::className()], ['class' => \skeeks\cms\grid\DateTimeColumnData::className(), 'attribute' => 'logged_at'], ['class' => \yii\grid\DataColumn::className(), 'filter' => \yii\helpers\Html::activeListBox($searchModel, 'role', \yii\helpers\ArrayHelper::merge(['' => ' - '], \yii\helpers\ArrayHelper::map(\Yii::$app->authManager->getRoles(), 'name', 'description')), ['size' => 1, 'class' => 'form-control']), 'value' => function (\skeeks\cms\models\User $model) {
$result = [];
if ($roles = \Yii::$app->authManager->getRolesByUser($model->id)) {
foreach ($roles as $role) {
$result[] = $role->description . " ({$role->name})";
}
}
return implode(', ', $result);
}, 'format' => 'html', 'label' => \Yii::t('skeeks/cms', 'Roles')], ['class' => \skeeks\cms\grid\BooleanColumn::className(), 'attribute' => "active"], ['class' => \yii\grid\DataColumn::className(), 'label' => "Смотреть", 'value' => function (\skeeks\cms\models\CmsUser $model) {
return \yii\helpers\Html::a('<i class="glyphicon glyphicon-arrow-right"></i>', $model->getProfileUrl(), ['target' => '_blank', 'title' => \Yii::t('skeeks/cms', 'Watch to site (opens new window)'), 'data-pjax' => '0', 'class' => 'btn btn-default btn-sm']);
}, 'format' => 'raw'], ['class' => \skeeks\cms\grid\DateTimeColumnData::className(), 'attribute' => 'last_activity_at', 'visible' => false]], $autoColumns)]);
?>
<? $pjax::end(); ?>
示例10: run
/**
* @inheritdoc
*/
public function run()
{
$this->registerClientScript();
Html::addCssClass($this->options, 'form-control');
$this->options['multiple'] = true;
if ($this->hasModel()) {
return Html::activeListBox($this->model, $this->attribute, $this->items, $this->options);
} else {
return Html::listBox($this->name, $this->selection, $this->items, $this->options);
}
}
示例11:
?>
<?php
echo Html::tag('p', $item['category']['name'], ['class' => 'form-control-static', 'data-form-switch' => 'radio']);
?>
<?php
} else {
?>
<?php
echo Html::activeListBox($item, 'category_id', $categoryNames, ['class' => 'form-control', 'data-form-switch' => 'radio', 'size' => 1]);
?>
<?php
}
?>
-->
<?php
echo Html::activeListBox($item, 'category_id', $categoryNames, ['class' => 'form-control', 'data-form-switch' => 'radio', 'size' => 1]);
?>
<?php
$this->registerJs('$("[data-form-switch=radio]").formSwitch(' . $item->getAttributeItems('categoryType', 1, true) . ', "' . $item['category']['id'] . '", ".form-group.category_name .form-control-static", ' . $categoryTypes . ', ' . $categoryTypeItems . ');', 3);
?>
</div>
</div>
<div class="form-group category_name">
<?php
echo Html::label(\Yii::t($module->messageCategory, '{attribute} {action}', ['attribute' => \Yii::t($module->messageCategory, 'category'), 'action' => \Yii::t($module->messageCategory, 'type')]), null, ['class' => 'control-label col-sm-2']);
?>
<div class="col-sm-4">
<?php
echo Html::tag('p', null, ['class' => 'form-control-static']);
?>
</div>