Ошибка{"more":false,"results":{"id":0,"text":"Ничего не найдено"}}
An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in /Users/maksimvorozcov/Web/eventdance/backend/modules/profile/controllers/DefaultController.php on line 192. in /Users/maksimvorozcov/Web/eventdance/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /Users/maksimvorozcov/Web/eventdance/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /Users/maksimvorozcov/Web/eventdance/vendor/yiisoft/yii2/web/ErrorHandler.php(135): yii\web\Response->send()
#2 /Users/maksimvorozcov/Web/eventdance/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\web\HeadersAlreadySentException))
#3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\HeadersAlreadySentException))
#4 {main}
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in /Users/maksimvorozcov/Web/eventdance/backend/modules/profile/controllers/DefaultController.php on line 192. in /Users/maksimvorozcov/Web/eventdance/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /Users/maksimvorozcov/Web/eventdance/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()
#1 /Users/maksimvorozcov/Web/eventdance/vendor/yiisoft/yii2/base/Application.php(392): yii\web\Response->send()
#2 /Users/maksimvorozcov/Web/eventdance/backend/web/index.php(36): yii\base\Application->run()
#3 {main}
Контроллерpublic function actionDancer() {
$search = Yii::$app->request->post('search')['term'];
$out = ['more' => false];
if (!is_null($search)) {
$query = Profile::find()
->orderBy('name')
->andFilterWhere(['like', 'name', $search])
->all();
foreach ($query as $i => $data) {
$out['results'][$i] = ['id' => $data->id, 'text' => $data->getFullName()];
}
} else {
$out['results'] = ['id' => 0, 'text' => 'Ничего не найдено'];
}
echo Json::encode($out);
}
View<?= $form->field($model, 'user_id')->widget(Select2::classname(), [
'id' => 'user',
'options' => [
'placeholder' => 'Выберите танцора...',
'class' => 'form-control',
],
'initValueText' => !empty($model->user_id) ? $model->profile->getFullName() :'',
'pluginOptions' => [
'allowClear' => true,
'minimumInputLength' => 1,
'ajax' => [
'url' => Url::to(['/profile/default/dancer']),
'dely' => 250,
'type' => 'post',
'dataType' => 'json',
'data' => new JsExpression('function(term,page) { return {search:term}; }'),
'results' => new JsExpression('function(data,page) { return {results:data.results}; }'),
],
],
]);?>