在kartik DepDrop中,二级下拉菜单出现错误


In kartik DepDrop Am getting Error for second level dropdown

我正在尝试使用kartik depdrop yii2扩展的Dependent下拉菜单。这个依赖下拉列表的过程是,如果我选择一个company_name,它会显示依赖的employeeCode,然后如果选择一个employeecode,它将显示依赖的EmployeeName。

事实上,第一个级别运行得很好,如果我选择一个company_name,它会显示employee_code,这个操作运行得很完美,但第二个级别的问题。如果我选择一个employee_code,它需要向我显示employe_name,则此操作不起的作用

我收到错误作为

PHP Notice 'yii'base'ErrorException' with message 'Undefined variable: out' 
in C:'wamp'www'fiducial'backend'models'Employee.php:140

这里我已经粘贴了下面的代码,请帮助我解决问题

<?= $form->field($model, 'company_name')->dropDownList($data1,
                ['prompt' => 'Select Company Name..', 'id' => 'cat-id']
            ) ?>
<?= $form->field($model, 'employee_id')->widget(DepDrop::classname(), [
                'options'=>['id'=>'subcat-id'],
                'pluginOptions'=>[
                    'depends'=>['cat-id'],
                    'placeholder'=>'Select...',
                    'url'=>yii'helpers'Url::to(['claim/subcat'])
                ]
            ]);  ?>
 <?php $form->field($model, 'employee_name')->widget(DepDrop::classname(), [
            'pluginOptions'=>[
                'depends'=>['cat-id', 'subcat-id'],
                'placeholder'=>'Select...',
                'url'=>yii'helpers'Url::to(['claim/claimername'])
            ]
        ]); ?>

控制器

   public function actionSubcat() 
    {
        $out = [];
        if (isset($_POST['depdrop_parents'])) {
            $parents = $_POST['depdrop_parents'];
            if ($parents != null) {
                $cat_id = $parents[0];
                $out = Employee::getSubCatList($cat_id);
                echo Json::encode($out);
                return;
            }
        }
        echo Json::encode(['output'=>'', 'selected'=>'']);
    }
public function actionClaimername() 
    {
        $out = [];
        if (isset($_POST['depdrop_parents'])) {
            $ids = $_POST['depdrop_parents'];
            $cat_id = empty($ids[0]) ? null : $ids[0];
            $subcat_id = empty($ids[1]) ? null : $ids[1];
            if ($cat_id != null) {
               $data = Employee::getClaimerNameList($cat_id, $subcat_id);
                /**
                 * the getProdList function will query the database based on the
                 * cat_id and sub_cat_id and return an array like below:
                 *  [
                 *      'out'=>[
                 *          ['id'=>'<prod-id-1>', 'name'=>'<prod-name1>'],
                 *          ['id'=>'<prod_id_2>', 'name'=>'<prod-name2>']
                 *       ],
                 *       'selected'=>'<prod-id-1>'
                 *  ]
                 */
               echo Json::encode($out);
               return;
            }
        }
        echo Json::encode(['output'=>'', 'selected'=>'']);
    }

型号

public static function getSubCatList($cat_id)
    {
        $data = Employee::find()
                ->where(['importcompany_id' => $cat_id])
                ->andWhere(['!=', 'status', 'Deleted'])
                ->groupBy(['employee_id'])
                ->asArray()
                ->all();
        foreach ($data as $dat) {
            $out[] = ['id' => $dat['id'], 'name' => $dat['employee_id']];
        }
        return $output = [
            'output' => $out,
            'selected' => ''
        ];
    }
    public static function getClaimerNameList($cat_id, $subcat_id)
    {
        $data = Employee::find()
                ->where(['importcompany_id' => $cat_id])
                ->andWhere(['employee_id' => $subcat_id])
                ->asArray()
                ->all();
        $selected = '';
        foreach ($data as $dat => $datas) {
            $out[] = ['id' => $datas['id'], 'name' => $datas['name']];
            if($dat == 0){
                    $aux = $datas['id'];
                }
            ($datas['id'] == $cat_id) ? $selected = $cat_id : $selected = $aux;
        }
        return $output = [
            'output' => $out,
            'selected' => $selected
        ];
    }

您忘记声明out变量。

您应该在getSubCatList()getClaimerNameList()函数中声明out变量。如数组变量的CCD_ 5。