backend\controllers\UserController::actionMobileFilter PHP Method

actionMobileFilter() public method

public actionMobileFilter ( $q = null, $id = null )
    public function actionMobileFilter($q = null, $id = null)
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        $output = ['results' => ['id' => '', 'text' => '']];
        if (!is_null($q)) {
            $sql = 'SELECT id, mobile AS text FROM ' . User::tableName() . ' WHERE mobile LIKE :like ORDER BY mobile ASC LIMIT 25';
            $output['results'] = Yii::$app->db->createCommand($sql, [':like' => "%{$q}%"])->queryAll();
        } elseif ($id > 0 && ($user = User::findOne($id))) {
            $output['results'] = ['id' => $id, 'text' => $user->mobile];
        }
        return $output;
    }