controllers/CategoriesController.php
public function actionCreate()
    {
        $model = new Categories;

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            if (Yii::$app->request->isAjax) 
            {
                header('Content-type: application/json');
                echo Json::encode(['status'=>'DONE','model'=>$model]);
                exit();
            }
            else
            {
                return $this->redirect(['view', 'id' => $model->id]);
            }
        }
        return $this->render('create', [
            'model' => $model,
        ]);
    }
public function actionCreate()
    {
        $model = new Categories;

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            if (Yii::$app->request->isAjax) 
            {
                header('Content-type: application/json');
                echo Json::encode(['status'=>'DONE','model'=>$model]);
                exit();
            }
            else
            {
                return $this->redirect(['view', 'id' => $model->id]);
            }
        }
        return $this->render('create', [
            'model' => $model,
        ]);
    }
public function actionCreate ( ) { $ model = new Categories ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { if ( Yii :: $ app -> request -> isAjax ) { header ( 'Content-type: application/json' ) ; echo Json :: encode ( [ 'status' => 'DONE' , 'model' => $ model ] ) ; exit ( ) ; } else { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; }
Creates a new Categories model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Categories model . If creation is successful the browser will be redirected to the view page .