dongxing6802 2018-03-22 13:11
浏览 42
已采纳

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

In Yii2 I have integrated Kartik Depdrop widget. When I am using the Indian state and city in the table, it is working fine. but once I update the same table with US state and city,

the dependent field is not filled up and in firebug response is shown correctly but along with error - headers already sent exception like:

An Error occurred while handling another error: yii\web\HeadersAlreadySentException: Headers already sent in /var/www/clients/client2/web206/web/controllers/UserController.php on line 159. in /var/www/clients/client2/web206/web/vendor/yiisoft/yii2/web/Response.php:366

The relevant code is like this:

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'=>'']);

    }

So I am not able to make, what is causing the issue and how I can fix it.

only difference to me it looks like is the number of database entries are more compared to Indian state and city.

  • 写回答

1条回答 默认 最新

  • doq13207 2018-03-22 17:11
    关注
    echo Json::encode(['output'=>$out,'selected'=>'']); // this is line 159
    return;
    

    ALTER FOR

    return Json::encode(['output'=>$out,'selected'=>'']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?