/** * Display list of all users in json format * * @param string $search - username * @return mixed */ public function actionUserList($search = null, $id = null) { $out = ['more' => false]; if (!is_null($search)) { $query = new Query(); $query->select('id, username AS text')->from(User::tableName())->where(['like', 'username', $search])->limit(20); $command = $query->createCommand(); $data = $command->queryAll(); $out['results'] = array_values($data); } elseif ($id > 0) { $out['results'] = ['id' => $id, 'text' => $this->findModel($id)->username]; } else { $out['results'] = ['id' => 0, 'text' => 'No matching records found']; } echo Json::encode($out); }