Yii2 Depdrop - TypeError:'在'操作数obj ERROR中无效'

时间:2017-03-27 21:10:05

标签: php yii2 dropdown kartik-v

我正在使用Kartik DepDrop小部件来下拉选项。我已成功展示了这些选项。

但是我的firebug控制台出现了这样的错误

TypeError: invalid 'in' operand obj

这是我的代码:

查看:

<?php
<div class="pib-data-form">
<?php $form = ActiveForm::begin(); ?>

<?php echo $form->field($model, 'transaction_type')->dropDownList(PibTransactionType::getOptions(), ['id' => 'parent_id']); ?>

<?=
$form->field($model, 'doc_type')->widget(DepDrop::classname(), [
    'type' => DepDrop::TYPE_SELECT2,
    'options' => ['id' => 'first_child_id'],
    'pluginOptions' => [
        'depends' => ['parent_id'],
        'placeholder' => 'Select...',
        'url' => Url::to(['pib-data/document-type'])
    ]
]);
?>

<?php
echo FileInput::widget([
    'name' => 'file_uploads',
    'language' => 'id',
    'options' => [
        'accept' => 'doc/*', 'file/*',
        'multiple' => true,
        'enableLabel' => true,
    ],
    'pluginOptions' => [
        'allowedFileExtensions' => ['xls', 'xlsx'],
        'uploadUrl' => Url::to(['/pib/pib-data/create']),
    ]
]);
?>

<?php ActiveForm::end(); ?>
</div>
<?php
$this->registerJS("
$('#w1').on('fileuploaded', function(event, data, previewId, index) {
    var response = data.response;
    $(location).attr('href', response.url);
}
);", View::POS_END);

控制器:

public function actionDocumentType() {
    $out = [];
    if (isset($_POST['depdrop_parents'])) {
        $parents = $_POST['depdrop_parents'];
        if ($parents != null) {
            $parent_id = $parents[0];
            $out = PibDocumentType::getOptionsbyTransactionType($parent_id);
            echo Json::encode(['output' => $out, 'selected' => '']);
            return;
        }
    }
    echo Json::encode(['output' => '', 'selected' => '']);
}

型号:

TransactionType.php

public static function getOptions(){
   $data=  static::find()->all();
   $value=(count($data)==0)? [''=>'']: \yii\helpers\ArrayHelper::map($data, 'id','name');

    return $value;
}

DocumentType.php

public static function getOptionsbyTransactionType($parent_id) {
    $data = static::find()->where(['transaction_type_id'=>$parent_id])->select(['id','name'])->asArray()->all();
    $value = (count($data) == 0) ? ['' => ''] : $data;        
    return $value;
}

错误是什么意思,我该如何解决?

0 个答案:

没有答案