本文整理汇总了PHP中yii\helpers\Html::radio方法的典型用法代码示例。如果您正苦于以下问题:PHP Html::radio方法的具体用法?PHP Html::radio怎么用?PHP Html::radio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Html
的用法示例。
在下文中一共展示了Html::radio方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
if (is_null($this->id)) {
if ($this->model instanceof Model) {
$this->id = Html::getInputId($this->model, $this->attribute);
} else {
$this->id = $this->getId();
}
}
if (is_null($this->name)) {
if ($this->model instanceof Model) {
$this->name = Html::getInputName($this->model, $this->attribute);
} else {
$this->name = $this->getId();
}
}
$this->options['id'] = $this->id;
$this->options['name'] = $this->name;
switch ($this->type) {
case 'checkbox':
if ($this->model instanceof Model) {
$this->options['label'] = null;
echo Html::activeCheckbox($this->model, $this->attribute, $this->options);
} else {
echo Html::checkbox($this->name, $this->checked, $this->options);
}
break;
case 'radio':
if ($this->model instanceof Model) {
$this->options['label'] = null;
echo Html::activeRadio($this->model, $this->attribute, $this->options);
} else {
echo Html::radio($this->name, $this->checked, $this->options);
}
break;
default:
throw new Exception('Invalid element type');
}
$this->register();
}
示例2: renderDataCellContent
/**
* @inheritdoc
*/
protected function renderDataCellContent($model, $key, $index)
{
$items = '';
foreach ($this->buttons as $value => $label) {
$items .= Html::label(Html::radio(null, $model->{$this->attribute} == $value, ['value' => $value]) . $label, $model->{$this->attribute} == $value, ['class' => 'btn ' . ($model->{$this->attribute} == $value ? 'btn-primary' : 'btn-default')]);
}
return Html::tag('div', $items, ['data-action' => 'toggle-column', 'data-attribute' => $this->attribute, 'data-id' => $model->id, 'data-model' => get_class($model), 'data-url' => Url::to($this->updateAction), 'data-toggle' => 'buttons', 'class' => 'btn-group-xs btn-group']);
}
示例3: radioListBosstrap
/**
* Print radio group in boostrap style
*
*/
public function radioListBosstrap($items, $options = [])
{
$mOptions = array_merge($options, ['class' => 'btn-group', 'data-toggle' => 'buttons', 'unselect' => null, 'item' => function ($index, $label, $name, $checked, $value) {
return '<label class="btn btn-default' . ($checked ? ' active' : '') . '">' . Html::radio($name, $checked, ['value' => $value, 'class' => 'project-status-btn']) . $label . '</label>';
}]);
return $this->radioList($items, $mOptions);
}
示例4: renderDataCellContent
/**
* @inheritdoc
*/
protected function renderDataCellContent($model, $key, $index)
{
if ($this->gridType == 'datatable-select') {
if (!$this->multiple) {
return Html::radio(rtrim($this->name, '[]'), false, ['value' => $key]);
} else {
return Html::checkBox($this->name, false, ['value' => $key]);
}
} else {
return parent::renderDataCellContent($model, $key, $index);
}
}
示例5: image
protected function image($image, $name)
{
echo Html::beginTag('div', ['class' => 'images-upload-item']);
echo Html::beginTag('div', ['class' => 'images-upload-item-content']);
echo Html::a(Html::img($image->getUrl('180x180')), $image->getUrl(), ['target' => '_blank']);
$checkbox = Html::checkbox($name . '[delete][' . $image->id . ']', false, ['label' => __('Delete')]);
echo Html::tag('div', $checkbox, ['class' => 'checkbox']);
if (!$image->default) {
$radio = Html::radio($name . '[default]', false, ['value' => $image->id, 'label' => __('Set default')]);
echo Html::tag('div', $radio, ['class' => 'radio']);
}
echo Html::endTag('div');
echo Html::endTag('div');
}
示例6: renderRadioInput
private function renderRadioInput()
{
$items = [];
foreach ($this->items as $key => $item) {
if (!is_array($item)) {
$options = $this->options;
$options['value'] = $key;
$options['label'] = $item;
$options['labelOptions'] = $this->labelOptions;
} else {
$options = ArrayHelper::getValue($item, 'options', []) + $this->options;
$options['value'] = ArrayHelper::getValue($item, 'value');
$options['label'] = ArrayHelper::getValue($item, 'label', false);
$options['labelOptions'] = ArrayHelper::getValue($item, 'labelOptions', []) + $this->labelOptions;
}
if ($this->inline) {
$options['container'] = '';
}
$items[] = $this->hasModel() ? Html::activeRadio($this->model, $this->attribute, $options) : Html::radio($this->name, $this->checked, $options);
}
$this->containerOptions['class'] = ArrayHelper::getValue($this->containerOptions, 'class', 'form-group');
print Html::tag('div', implode($this->separator, $items), $this->containerOptions);
}
示例7: run
/**
* Runs the widget.
*/
public function run()
{
if ($this->hasModel()) {
$value = Html::getAttributeValue($this->model, $this->attribute);
$name = Html::getInputName($this->model, $this->attribute);
} else {
$value = $this->value;
$name = $this->attribute;
}
$toogle = 'radiotab-' . Inflector::slug($name);
$content = $this->inline ? '' : '<div class="clearfix"></div>';
$content .= '<div id="' . $toogle . '" class="btn-group" data-toggle="buttons">';
if (is_array($this->items)) {
foreach ($this->items as $id => $label) {
$checked = $value == $id ? true : false;
$options = ['class' => 'btn btn-default' . ($checked ? ' active' : ''), 'data-toggle' => $toogle];
$radio = Html::radio($name, $checked, ['class' => 'non-styler', 'value' => $id]);
$content .= Html::a($radio . $label, null, $options);
}
}
$content .= '</div>';
return $content;
}
示例8: genField
private function genField($name, $setting, $options)
{
if (preg_match("/number|string/i", $setting->type)) {
return Html::textInput($name, $setting->value, $options);
} elseif (preg_match("/text/i", $setting->type)) {
return Html::textArea($name, $setting->value, $options);
} elseif (preg_match("/bool/i", $setting->type)) {
return Html::checkBox($name, $setting->value, array_merge($options, $this->checkboxOptions, ['template' => '']));
} elseif (preg_match("/dropdown/i", $setting->type)) {
$data = @unserialize($setting->options);
$data = is_array($data) ? $data : [];
return Html::dropDownList($name, $setting->value, $data, $options);
} elseif (preg_match("/radiolist/i", $setting->type)) {
$data = @unserialize($setting->options);
$data = is_array($data) ? $data : [];
$template = $this->radioTemplate;
$this->radioOptions['item'] = !$this->radioCallback ? function ($index, $label, $name, $checked, $value) use($template) {
return strtr($template, ['{input}' => Html::radio($name, $checked, ['value' => $value]), '{labelText}' => $label]);
} : $this->radioCallback;
return Html::radioList($name, $setting->value, $data, array_merge($options, $this->radioOptions));
} elseif (preg_match("/{dateradiolist}/i", $setting->type)) {
$data = @unserialize($setting->options);
$data = is_array($data) ? $data : [];
$template = $this->radioTemplate;
$this->radioOptions['item'] = function ($index, $label, $name, $checked, $value) use($template) {
return strtr($template, ['{input}' => Html::radio($name, $checked, ['value' => $value]), '{labelText}' => date($value, time())]);
};
return Html::radioList($name, $setting->value, array_combine($data, $data), array_merge($options, $this->radioOptions));
} elseif (preg_match("/timezone/i", $setting->type)) {
return Html::dropDownList($name, $setting->value, $this->getTimezones(), $options);
} elseif (preg_match("/date/i", $setting->type)) {
return DatePicker::widget(['name' => $name, 'type' => DatePicker::TYPE_INPUT, 'value' => date('d-m-Y', strtotime($setting->value)), 'pluginOptions' => ['autoclose' => true, 'format' => 'dd-M-yyyy']]);
} else {
return Html::textArea($name, $setting->value, $options);
}
}
示例9: radio
/**
* @inheritdoc
*/
public function radio($options = [], $enclosedByLabel = true)
{
$options = $this->mergeInputOptions($options, ['data-bind' => 'checked:' . $this->attribute, 'placeholder' => null]);
if ($enclosedByLabel) {
$this->parts['{input}'] = Html::radio($this->attribute, null, $options);
$this->parts['{label}'] = '';
} else {
if (isset($options['label']) && !isset($this->parts['{label}'])) {
$this->parts['{label}'] = $options['label'];
if (!empty($options['labelOptions'])) {
$this->labelOptions = $options['labelOptions'];
}
}
unset($options['label'], $options['labelOptions']);
$this->parts['{input}'] = Html::radio($this->attribute, null, $options);
}
return $this;
}
示例10: function
//$disabled = true; // replace with whatever check you use for each item
//$checked = false;
//if($value == 0){
// $checked = true;
//}
return Html::radio($name, $checked, ['value' => $value, 'label' => Html::encode($label)]);
}]);
}
if (Yii::$app->user->can("hrm") && $model->reasonApplication->type_id == -11 || Yii::$app->user->can('admin')) {
echo $form->field($model, 'hrm_ok')->radioList(array(1 => 'Accept ', 0 => ' Refuse'), ['item' => function ($index, $label, $name, $checked, $value) {
//$disabled = true; // replace with whatever check you use for each item
//$checked = false;
//if($value == 0){
// $checked = true;
//}
return Html::radio($name, $checked, ['value' => $value, 'label' => Html::encode($label)]);
}]);
}
?>
<div class="form-group">
<?php
echo Html::submitButton('Save', ['class' => 'btn btn-primary']);
?>
</div>
</div>
</div>
<?php
ActiveForm::end();
?>
</div>
示例11:
<div class="col-lg-offset-1 col-lg-11">
<?php
echo Html::input("text", "sec_answer", "autocom", ["required" => "required"]);
?>
</div>
</div>
<label>User type will be attached</label>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<ul>
<?php
foreach (UserType::find()->asArray()->all() as $key => $value) {
echo "<li>";
echo Html::radio("user_type", false, ["label" => $value["name"], "value" => $value["id"]]);
echo "</li>";
}
?>
</ul>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?php
echo Html::submitButton('Save', ['class' => 'btn btn-primary']);
?>
</div>
</div>
示例12: renderDataCellContent
/**
*
* render a radio button in Grid View
* @param mixed $model
* @param mixed $key
* @param int $index
* @return radio button
*/
protected function renderDataCellContent($model, $key, $index)
{
return Html::radio($this->name,false,['value' => $model->primaryKey]);
}
示例13: run
/**
* Renders the widget.
* <div class="custom_label">
* <input type="radio" class="" id="{*some_id*}" >
* <label for="{*some_id*}" class="radio_imitation"></label>
* <label for="{*some_id*}" class="radio_text">{*text*}</label>
* </div>
*/
public function run()
{
$this->registerClientScript();
$html = [];
if ($this->hasModel()) {
$fieldName = $this->attribute;
$valueField = $this->model->{$fieldName};
if (!is_null($this->nullString)) {
$item = [];
if (in_array($valueField, $this->list)) {
$id = $this->attrId . '-null';
$item[] = Html::radio($this->attrName, false, ArrayHelper::merge(['id' => $id, 'value' => ''], $this->options['input']));
$item[] = Html::label('', $id, $this->options['label1']);
$item[] = Html::label($this->nullString, $id, $this->options['label2']);
} else {
$id = $this->attrId . '-null';
$item[] = Html::radio($this->attrName, true, ArrayHelper::merge(['id' => $id, 'value' => ''], $this->options['input']));
$item[] = Html::label('', $id, $this->options['label1']);
$item[] = Html::label($this->nullString, $id, $this->options['label2']);
}
$html[] = Html::tag('div', join('', $item), $this->options['div']);
}
foreach ($this->list as $key => $value) {
$item = [];
$id = $this->attrId . '-' . $key;
if (is_null($valueField)) {
$checked = false;
} else {
$checked = $valueField == $key;
}
$item[] = Html::radio($this->attrName, $checked, ArrayHelper::merge(['id' => $id, 'value' => $key], $this->options['input']));
$item[] = Html::label('', $id, $this->options['label1']);
$item[] = Html::label($value, $id, $this->options['label2']);
$html[] = Html::tag('div', join('', $item), $this->options['div']);
}
}
echo join('', $html);
}
示例14: getApixRadioHtml
protected function getApixRadioHtml($form, $config, $field)
{
$model = $config['model'];
$fieldHtml = Html::radio($model . "[{$field->name}]", false, $field->options);
if ($config['label']) {
$fieldHtml = "<div class='frm-field'><label>{$field->label}</label>{$fieldHtml}<span class='error' cmt-error='{$field->name}'></span></div>";
} else {
$fieldHtml = "<div class='frm-field'>{$fieldHtml}<span class='error' cmt-error='{$field->name}'></span></div>";
}
return $fieldHtml;
}
示例15: function
<?php
echo $form->field($model, 'firm_id')->dropDownList(ArrayHelper::map(\app\models\Firm::find()->active()->orderBy('name asc')->all(), 'id', 'name'), ['prompt' => '']);
?>
<?php
echo $form->field($model, 'workplace_id')->dropDownList(ArrayHelper::map(\app\models\Workplace::find()->active()->all(), 'id', 'name'), ['prompt' => '']);
?>
<?php
echo $form->field($model, 'note')->textarea(['rows' => 6]);
?>
<?php
echo $form->field($model, 'rec_status_id')->radioList(ArrayHelper::map(\app\models\RecStatus::find()->active()->all(), 'id', 'name'), ['class' => 'btn-group', 'data-toggle' => 'buttons', 'unselect' => null, 'item' => function ($index, $label, $name, $checked, $value) {
return '<label class="btn btn-default' . ($checked ? ' active' : '') . '">' . Html::radio($name, $checked, ['value' => $value, 'class' => 'project-status-btn']) . $label . '</label>';
}]);
?>
<?php
echo $form->field($model, 'user_id')->dropDownList(ArrayHelper::map(\app\models\User::find()->active()->all(), 'id', 'name'), ['prompt' => '']);
?>
<?php
echo $form->field($model, 'dc')->textInput();
?>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<?php
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Save') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);