当前位置: 首页>>代码示例>>PHP>>正文


PHP Html::renderSelectOptions方法代码示例

本文整理汇总了PHP中yii\helpers\Html::renderSelectOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Html::renderSelectOptions方法的具体用法?PHP Html::renderSelectOptions怎么用?PHP Html::renderSelectOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\Html的用法示例。


在下文中一共展示了Html::renderSelectOptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 public function run()
 {
     SelectAsset::register($this->view);
     FilterAsset::register($this->view);
     $values = [];
     foreach ($this->data as $value) {
         $value = strval($value);
         $values[$value] = $value;
     }
     if (!$this->default) {
         $this->default = $this->multiple ? array_keys($values) : key($values);
     }
     $selected = $this->selected($this->default);
     // Setup options
     $options = ['id' => $this->name, 'name' => $this->name . '[]', 'style' => 'width: 300px;', 'class' => 'selectpicker'];
     $extra = ['title' => 'Not selected'];
     if ($this->multiple) {
         $extra['multiple'] = 'multiple';
     }
     if ($this->placeholder) {
         $extra['title'] = strval($this->placeholder);
     }
     $options = array_merge($options, $extra);
     if (!$this->method) {
         $this->method = 'get';
     }
     // Render
     echo Html::beginForm(Url::canonical(), $this->method, ['data-pjax' => '1', 'id' => $this->name]);
     echo Html::beginTag('select', $options, ['data-pjax' => '1']);
     echo Html::renderSelectOptions($selected, $values);
     echo Html::endTag("select");
     echo Html::endForm();
     parent::run();
 }
开发者ID:Polymedia,项目名称:BI-Platform-v3,代码行数:34,代码来源:Filter.php

示例2: run

 public function run()
 {
     $id = $this->getId();
     echo Html::beginForm(Url::canonical(), 'get', ['data-pjax' => '1', 'id' => $this->name]);
     echo Html::beginTag('div');
     echo Html::beginTag("select", ['id' => $id, 'multiple' => 'multiple', 'class' => 'invisible', 'style' => 'width: ' . $this->width . 'px;', 'name' => $this->name . '[]']);
     echo Html::renderSelectOptions($this->selectedValues, $this->_allValues);
     echo Html::endTag("select");
     echo Html::submitButton('OK', ['style' => 'margin: 0 5px;']);
     echo Html::endTag('div');
     echo Html::endForm();
     echo "<script type='text/javascript'>";
     echo "\$('#{$id}').removeClass('invisible');";
     echo "\$('#{$id}').multipleSelect()";
     echo "</script>";
 }
开发者ID:Polymedia,项目名称:BI-Platform-v3,代码行数:16,代码来源:MultipleSelect.php

示例3: actionNps

 /**
  * Рендерит html населенных пунктов для dropdown
  * @param int $id идентификатор района
  * @throws \yii\base\ExitException
  */
 public function actionNps($id)
 {
     $all = Np::find()->published()->where(["rajon_id" => $id])->orderBy(["title" => SORT_ASC])->all();
     $o = ["prompt" => ""];
     echo Html::renderSelectOptions(null, ArrayHelper::map($all, "id", "title"), $o);
     Yii::$app->end();
 }
开发者ID:frostiks25,项目名称:rzwebsys7,代码行数:12,代码来源:ListController.php

示例4: run

 public function run()
 {
     $parent_id = Yii::$app->request->get('parent_id');
     $modelClass = $this->model;
     if ($parent_id > 0) {
         return Html::renderSelectOptions('district', $modelClass::getRegion($parent_id));
     } else {
         return [];
     }
 }
开发者ID:chenkby,项目名称:yii2-region,代码行数:10,代码来源:RegionAction.php

示例5: init

 public function init()
 {
     if (!$this->model) {
         throw new InvalidParamException('model不能为null!');
     }
     if (empty($this->province) || empty($this->city)) {
         throw new InvalidParamException('province和city不能为空!');
     }
     $cityId = Html::getInputId($this->model, $this->city['attribute']);
     if (empty($this->city['options']['prompt'])) {
         $this->city['options']['prompt'] = '选择城市';
     }
     $cityDefault = Html::renderSelectOptions('city', ['' => $this->city['options']['prompt']]);
     if (!empty($this->district)) {
         if (empty($this->district['options']['prompt'])) {
             $this->district['options']['prompt'] = '选择县/区';
         }
         $districtId = Html::getInputId($this->model, $this->district['attribute']);
         $districtDefault = Html::renderSelectOptions('district', ['' => $this->district['options']['prompt']]);
         $this->city['options'] = ArrayHelper::merge($this->city['options'], ['onchange' => "\r\n                if(\$(this).val()!=''){\r\n                    \$.get('{$this->url}?parent_id='+\$(this).val(),function(data){\r\n                        \$('#{$districtId}').html('{$districtDefault}'+data);\r\n                    })\r\n                }else{\r\n                    \$('#{$districtId}').html('{$districtDefault}');\r\n                }\r\n            "]);
     }
     $this->province['options'] = ArrayHelper::merge($this->province['options'], ['onchange' => "\r\n                if(\$(this).val()!=''){\r\n                    \$.get('{$this->url}?parent_id='+\$(this).val(),function(data){\r\n                        \$('#{$cityId}').html('{$cityDefault}'+data);\r\n                    })\r\n                }else{\r\n                    \$('#{$cityId}').html('{$cityDefault}');\r\n                }\r\n                \$('#{$districtId}').html('{$districtDefault}');\r\n            "]);
 }
开发者ID:chenkby,项目名称:yii2-region,代码行数:23,代码来源:Region.php

示例6: generateForm

 private function generateForm($fields, $data = null)
 {
     $result = '';
     foreach ($fields as $field) {
         $value = !empty($data->{$field->name}) ? $data->{$field->name} : null;
         if ($field->type === 'string') {
             $result .= '<div class="form-group"><label>' . $field->title . '</label>' . Html::input('text', "Data[{$field->name}]", $value, ['class' => 'form-control']) . '</div>';
         } elseif ($field->type === 'text') {
             $result .= '<div class="form-group"><label>' . $field->title . '</label>' . Html::textarea("Data[{$field->name}]", $value, ['class' => 'form-control']) . '</div>';
         } elseif ($field->type === 'boolean') {
             $result .= '<div class="checkbox"><label>' . Html::checkbox("Data[{$field->name}]", $value, ['uncheck' => 0]) . ' ' . $field->title . '</label></div>';
         } elseif ($field->type === 'select') {
             $options = ['' => Yii::t('easyii/customers', 'Select')];
             foreach ($field->options as $option) {
                 $options[$option] = $option;
             }
             $result .= '<div class="form-group"><label>' . $field->title . '</label><select name="Data[' . $field->name . ']" class="form-control">' . Html::renderSelectOptions($value, $options) . '</select></div>';
         } elseif ($field->type === 'checkbox') {
             $options = '';
             foreach ($field->options as $option) {
                 $checked = $value && in_array($option, $value);
                 $options .= '<br><label>' . Html::checkbox("Data[{$field->name}][]", $checked, ['value' => $option]) . ' ' . $option . '</label>';
             }
             $result .= '<div class="checkbox well well-sm"><b>' . $field->title . '</b>' . $options . '</div>';
         }
     }
     return $result;
 }
开发者ID:engmohamedamer,项目名称:testone,代码行数:28,代码来源:ItemsController.php

示例7: implode

    <?php 
foreach ($model->fields as $field) {
    ?>
        <tr>
            <td><?php 
    echo Html::input('text', null, $field->name, ['class' => 'form-control field-name']);
    ?>
</td>
            <td><?php 
    echo Html::input('text', null, $field->title, ['class' => 'form-control field-title']);
    ?>
</td>
            <td>
                <select class="form-control field-type">
                    <?php 
    echo Html::renderSelectOptions($field->type, Category::$fieldTypes);
    ?>
                </select>
            </td>
            <td>
                <textarea class="form-control field-options" placeholder="<?php 
    echo Yii::t('easyii/catalog', 'Type options with `comma` as delimiter');
    ?>
" <?php 
    echo !$field->options ? 'style="display: none;"' : '';
    ?>
 ><?php 
    echo is_array($field->options) ? implode(',', $field->options) : '';
    ?>
</textarea>
            </td>
开发者ID:radiegtya,项目名称:easyii,代码行数:31,代码来源:fields.php

示例8: actionGolferSearch

 public function actionGolferSearch($id, $target, $term = '')
 {
     $model = $this->findCompetition($id);
     $golfers = Golfer::find()->all();
     $availables = [];
     foreach ($golfers as $golfer) {
         $availables[$golfer->id] = $golfer->name;
     }
     $registrations = Registration::find()->where(['competition_id' => $id, 'status' => array(Registration::STATUS_PENDING, Registration::STATUS_REGISTERED)])->all();
     $registereds = [];
     foreach ($registrations as $registration) {
         $registereds[$registration->golfer_id] = $availables[$registration->golfer_id];
         unset($availables[$registration->golfer_id]);
     }
     $result = [];
     if (!empty($term)) {
         foreach (${$target} as $golfer) {
             if (strpos($golfer, $term) !== false) {
                 $id = Golfer::findOne(['name' => $golfer]);
                 $result[$id->id] = $golfer;
             }
         }
     } else {
         $result = ${$target};
     }
     return Html::renderSelectOptions('', $result);
 }
开发者ID:kleitz,项目名称:golfleague,代码行数:27,代码来源:RegistrationController.php

示例9: actionSections

 /**
  * Action method for auto completion sections by the given parent category.
  * @param integer $id of the category to be used to auto complete sections.
  * @return string|Response action method execution result.
  */
 public function actionSections($id)
 {
     $sections = Section::findAll(['category_id' => $id]);
     $items = array_merge(['(choose section)'], ArrayHelper::map($sections, 'id', 'title'));
     return Html::renderSelectOptions(null, $items);
 }
开发者ID:keltstr,项目名称:yii2-forum-1,代码行数:11,代码来源:TopicController.php

示例10: actionRoleSearch

 /**
  * @param $id
  * @param string $target
  * @param string $term
  * @return string
  */
 public function actionRoleSearch($id, $target, $term = '')
 {
     $result = ['Roles' => [], 'Permission' => [], 'Routes' => []];
     $authManager = Yii::$app->authManager;
     if ($target == 'available') {
         $children = array_keys($authManager->getChildren($id));
         $children[] = $id;
         foreach ($authManager->getRoles() as $name => $role) {
             if (in_array($name, $children)) {
                 continue;
             }
             if (empty($term) or strpos($name, $term) !== false) {
                 $result['Roles'][$name] = $name;
             }
         }
         foreach ($authManager->getPermissions() as $name => $role) {
             if (in_array($name, $children)) {
                 continue;
             }
             if (empty($term) or strpos($name, $term) !== false) {
                 $result[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name;
             }
         }
     } else {
         foreach ($authManager->getChildren($id) as $name => $child) {
             if (empty($term) or strpos($name, $term) !== false) {
                 if ($child->type == Item::TYPE_ROLE) {
                     $result['Roles'][$name] = $name;
                 } else {
                     $result[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name;
                 }
             }
         }
     }
     return Html::renderSelectOptions('', array_filter($result));
 }
开发者ID:uqiauto,项目名称:wxzuan,代码行数:42,代码来源:RoleController.php

示例11: actionAssignrole

 /**
  * 给用户分配角色
  * @param $id
  * @return string
  */
 public function actionAssignrole($id)
 {
     $auth = Yii::$app->authManager;
     $model = TAdmUser::findOne($id);
     if (Yii::$app->request->isPost) {
         $action = Yii::$app->request->get('action');
         $roles = Yii::$app->request->post('roles');
         if ($action == 'assign') {
             foreach ($roles as $rolename) {
                 $role = $auth->getRole($rolename);
                 $auth->assign($role, $id);
             }
         } else {
             foreach ($roles as $rolename) {
                 $role = $auth->getRole($rolename);
                 $auth->revoke($role, $id);
             }
         }
         //所有角色
         $allroles = ArrayHelper::map($auth->getRoles(), 'name', 'name');
         //所有已选择的角色
         $selectedroles = ArrayHelper::map($auth->getRolesByUser($id), 'name', 'name');
         $res = [Html::renderSelectOptions('', array_diff($allroles, $selectedroles)), Html::renderSelectOptions('', $selectedroles)];
         Yii::$app->response->format = Response::FORMAT_JSON;
         return $res;
     }
     //获取已有角色
     $assignedroles = ArrayHelper::map($auth->getRolesByUser($id), 'name', 'name');
     //获取所有角色
     $allroles = ArrayHelper::map($auth->getRoles(), 'name', 'name');
     //未被选择的角色
     $roles = array_diff($allroles, $assignedroles);
     return $this->render('assignrole', ['roles' => $roles, 'assignedroles' => $assignedroles, 'model' => $model, 'id' => $id]);
 }
开发者ID:tqsq2005,项目名称:yga,代码行数:39,代码来源:RbacController.php

示例12: actionAttributes

 /**
  * Return rendered options for attribute select
  * @param $entityType
  * @return string
  */
 public function actionAttributes($entityType)
 {
     $attributes = Facet::getSearchableAttributes($entityType);
     $options = ['prompt' => ''];
     return Html::renderSelectOptions(null, $attributes, $options);
 }
开发者ID:manyoubaby123,项目名称:imshop,代码行数:11,代码来源:FacetController.php

示例13: actionGetDroDownDepValues

 /**
  * Get Values for Dependent DropDownList.
  * @author juan.gaviria@dsotogroup.com | Mariusz Soltys (https://github.com/marsoltys)
  */
 public function actionGetDroDownDepValues()
 {
     $post = $_POST;
     /**@var \yii\db\ActiveRecord $model*/
     $model = new $post['model']();
     $query = $model::findAll([$post['varname'] => $post[$post['varname']]]);
     $data = ArrayHelper::map($query, 'id', $post['optionDestName']);
     echo Html::renderSelectOptions('', $data, $options = ['prompt' => 'Select...']);
 }
开发者ID:marsoltys,项目名称:yii2user,代码行数:13,代码来源:ProfileFieldController.php

示例14: actionRouteSearch

 /**
  * Search Route
  * @param string $target
  * @param string $term
  * @param string $refresh
  * @return array
  */
 public function actionRouteSearch($target, $term = '', $refresh = '0')
 {
     if ($refresh == '1') {
         $this->invalidate();
     }
     $result = [];
     $manager = Yii::$app->getAuthManager();
     $existsOptions = [];
     $exists = array_keys($manager->getPermissions());
     $routes = $this->getAppRoutes();
     if ($target == 'new') {
         foreach ($routes as $route) {
             if (in_array($route, $exists)) {
                 continue;
             }
             if (empty($term) or strpos($route, $term) !== false) {
                 $result[$route] = $route;
             }
         }
     } else {
         foreach ($exists as $name) {
             if ($name[0] !== '/') {
                 continue;
             }
             if (empty($term) or strpos($name, $term) !== false) {
                 $result[$name] = $name;
             }
             // extract route part from $name
             $r = explode('&', $name);
             if (empty($r[0]) || !in_array($r[0], $routes)) {
                 $existsOptions[$name] = ['class' => 'lost'];
             }
         }
     }
     $options = $target == 'new' ? [] : ['options' => $existsOptions];
     return Html::renderSelectOptions('', $result, $options);
 }
开发者ID:hoangngk,项目名称:angular-blog,代码行数:44,代码来源:RouteController.php

示例15: actionGetCiudadesRegion

 public function actionGetCiudadesRegion($region_id, $empty = true)
 {
     if ($empty) {
         $options = ['' => 'Escoge ciudad'];
     }
     $ciudades = Region::find()->where(['id' => $region_id])->one()->ciudads;
     $ciudades = ArrayHelper::map($ciudades, 'id', 'nombre');
     asort($ciudades);
     $options += $ciudades;
     echo Html::renderSelectOptions('', $options);
 }
开发者ID:fernandrez,项目名称:ipcbsas,代码行数:11,代码来源:CiudadController.php


注:本文中的yii\helpers\Html::renderSelectOptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。