//controller层 public function actionSearchTitle ($q) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $out = ['results' => ['id' => '', 'text' => '']]; if (!$q) { return $out; } $data = Article::find() ->select('id, title as text') ->andFilterWhere(['like', 'title', $q]) ->limit(50) ->asArray() ->all(); $out['results'] = array_values($data); return $out; }
yii2组件之下拉框带搜索功能的示例代码(yii(2)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/d9838e34dd04308ed3441e31ecb79a9c.html