/** * Creates a new Campaign model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Campaign(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $response = ['action' => 'reload-page', 'form' => '']; $request = Yii::$app->request; $model = new Campaign(); $model->loadDefaultValues(); if ($request->isAjax && $request->isPost) { if ($model->load($request->post())) { $model->startDate = isset($model->startDate) ? date('U', strtotime($model->startDate)) : null; $model->endDate = isset($model->endDate) ? date('U', strtotime($model->endDate)) : null; $model->save(); return $response; } } $code = Yii::$app->request->get('code'); $form = Yii::$app->controller->renderPartial('@frontend/views/campaign/_form', ['model' => $model, 'code' => $code], true); return ['action' => 'create', 'form' => $form]; }