1

目前,我有一个现有代码可以根据表 User 的 ban_time 字段将用户状态显示为“非活动”或“活动”。当用户状态为“非活动”时,ban_time 字段将按当前时间跨度更新(我猜它使用外部包装插件)

$form->field($user, 'ban_time')->widget(SwitchInput::classname(), [
            'type' => SwitchInput::CHECKBOX,
            'containerOptions' => ['class' => 'inner-form-group'],
            'pluginOptions' => [
                'state' => empty($user->ban_time),
                'handleWidth' => 60,
                'onText' => 'Active',
                'offText' => 'Inactive'
            ],
            'pluginEvents' => [
                "switchChange.bootstrapSwitch" => "function(event, state) { $('[name=\'User[ban_time]\']').val(state ? 0 : 1) }",
            ]
        ])->label('Status'); 

现在,我需要添加更多状态而不是“非活动”或“活动”。所以我想将此字段更改为 dropDownList 但是在更改用户状态时,ban_time 没有更改

$form->field($user, 'ban_time')->dropDownList(
            [empty($user->ban_time) =>'Active', !empty($user->ban_time) =>'Inactive']
        )->label('Status'); 

请帮助我如何更改它

4

2 回答 2

1

您可以将表单元素设置为 dropDownList 为

     $items = [1 =>'Active', 0 =>'Inactive' ,2 => 'Subscribed' ,3 => 'Deleted'];
     $form->field($user, 'ban_time')->dropDownList($items)->label('Status'); 

请参阅下拉列表

于 2015-11-17T11:09:14.023 回答
1

例如,如果您有如下所示的下拉列表

  echo $form->dropDownListGroup(
                    $model, 'status', array(
                'wrapperHtmlOptions' => array(),
                'widgetOptions' => array(
                    'data' =>$model->getDropdownvalue(),
                    'htmlOptions' => array(
                        'prompt' => 'Select Project',
                        'ajax' => array(
                                'type' => 'POST',
                                'url' => your url,
                                //'dataType' => 'json',
                                'data'=>array('status'=>'js:this.value'),

                              )

在您的控制器中,您将使用 url 获得下拉列表的值

public function actiondropdownvalue(){
$model = new status();
        $status = $_POST['status'];
       $model->save();

这个例子只是展示了它是如何工作的。您将需要用户 ID 来保存特定用户的状态以更新或保存状态。

于 2015-11-18T06:43:30.933 回答