首页 文章

Yii2 Kartik依赖下拉列表 - 标头已发送异常

提问于
浏览
0

在Yii2中,我集成了Kartik Depdrop小部件 . 当我在 table 上使用印度的州和城市时,它工作正常 . 但是一旦我用美国州和市更新同一张 table ,

依赖字段没有填满,并且在firebug响应中显示正确,但同时显示错误 - 标头已发送异常,如:

处理另一个错误时出错:yii \ web \ HeadersAlreadySentException:已在/ var / www / clients / client2中第159行的/var/www/clients/client2/web206/web/controllers/UserController.php中发送的标头/web206/web/vendor/yiisoft/yii2/web/Response.php:366

相关代码如下:

public function actionSubcat() {
$out = [];
if (isset($_POST['depdrop_parents'])) {
$parents = $_POST['depdrop_parents'];
if ($parents != null) {
$cat_id = $parents[0];
$out = UserProfile::GetCity($cat_id);
// the getSubCatList function will query the database based on the
// cat_id and return an array like below:
// [
// ['id'=>'<sub-cat-id-1>', 'name'=>'<sub-cat-name1>'],
// ['id'=>'<sub-cat_id_2>', 'name'=>'<sub-cat-name2>']
// ]
echo Json::encode(['output'=>$out,'selected'=>'']); // this is line 159
    return;
 }
         }
         echo Json::encode(['output'=>'','selected'=>'']);

    }

所以我无法做出,导致问题的原因以及如何解决问题 .

与我不同的是,与印度的州和城市相比,数据库条目的数量更多 .

1 回答

  • 1

    echo Json :: encode(['output'=> $ out,'selected'=>'']); //这是第159行返回;

    改变

    return Json :: encode(['output'=> $ out,'selected'=>'']);

相关问题