backend/controllers/PostController.php
/**
     * Search POST model via AJAX with JSON as the response.
     */
Search POST model via AJAX with JSON as the response.
Search POST model via AJAX with JSON as the response .
public function actionAjaxSearch()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        $query = Post::find()
            ->select(['id', 'title'])
            ->andWhere(['like', 'title', Yii::$app->request->post('title')])
            ->limit(10);
        if ($postType = Yii::$app->request->post('type')) {
            $query->andWhere(['type' => $postType]);
        }
        return $query->all();
    }
public function actionAjaxSearch ( ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; $ query = Post :: find ( ) -> select ( [ 'id' , 'title' ] ) -> andWhere ( [ 'like' , 'title' , Yii :: $ app -> request -> post ( 'title' ) ] ) -> limit ( 10 ) ; if ( $ postType = Yii :: $ app -> request -> post ( 'type' ) ) { $ query -> andWhere ( [ 'type' => $ postType ] ) ; } return $ query -> all ( ) ; }
Search POST model via AJAX with JSON as the response.
Search POST model via AJAX with JSON as the response .