modules/admin/controllers/PromoCodeController.php
/**
     * Creates a new PromoCode model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new PromoCode model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new PromoCode model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new PromoCode();
        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($model);
        }
        if ($model->load(Yii::$app->request->post())) {
            $model->user_id = Yii::$app->user->identity->id;
            if($model->save()){
                Yii::$app->session->setFlash(Growl::TYPE_SUCCESS, "Promo code created successfully.");
            }else{
                Yii::$app->session->setFlash(Growl::TYPE_DANGER, "Error while creating Promo code.");
            }
            return $this->redirect(['index']);
        }
        return $this->render('create', [
            'model' => $model,
        ]);
    }
public function actionCreate ( ) { $ model = new PromoCode ( ) ; if ( Yii :: $ app -> request -> isAjax && $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; return ActiveForm :: validate ( $ model ) ; } if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ model -> user_id = Yii :: $ app -> user -> identity -> id ; if ( $ model -> save ( ) ) { Yii :: $ app -> session -> setFlash ( Growl :: TYPE_SUCCESS , " Promo code created successfully. " ) ; } else { Yii :: $ app -> session -> setFlash ( Growl :: TYPE_DANGER , " Error while creating Promo code. " ) ; } return $ this -> redirect ( [ 'index' ] ) ; } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; }
Creates a new PromoCode model.
Creates a new PromoCode model .
// Model validation with ajax