response->format = Response::FORMAT_JSON; $out = [ 'results' => [ 'id' => '', 'text' => '' ] ]; if (!is_null($q)) { $data = Merchant::find() ->select('id, title as text') ->where(['like', 'title', $q]) ->andWhere(['status' => StatusEnum::ENABLED]) ->limit(10) ->asArray() ->all(); $out['results'] = array_values($data); } elseif ($id > 0) { $out['results'] = ['id' => $id, 'text' => Merchant::findOne($id)->mobile]; } return $out; } }