當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。