0
votes

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
Why are you generating output in a controller? Sounds like someone needs to go read up on some MVC basics first of all. - CBroe
@CBroe - you may be quite right, but this is the extension by Kartik, who has so many extensions for Yii2. and for this extension the guide clearly instructs like that. I admit I am not an expert in Yii2, but assuming someone have host of extension and being used by the community, I assume that it is the correct way of doing it. - demos.krajee.com/widget-details/depdrop - Joshi
@CBroe - can you please suggest how I can fix that? - Joshi

1 Answers

2
votes
echo Json::encode(['output'=>$out,'selected'=>'']); // this is line 159
return;

ALTER FOR

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