/** * Creates a new Noticia model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Noticia(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id, 'created_by' => $model->created_by]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Noticia model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Noticia(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->fecha = date('Y-m-d h:m:s'); $model->save(); return $this->redirect(['view', 'id' => $model->id_noticia]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Noticia model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Noticia(); if ($model->load(Yii::$app->request->post())) { $model->idUsuario = Yii::$app->user->identity->idUsuario; $model->save(); return $this->redirect(['view', 'id' => $model->idNoticia]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Noticia model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Noticia(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { // if ($model->load(Yii::$app->request->post())) { // Yii::$app->response->format = 'json'; // return \yii\widgets\ActiveForm::validate($model); if (!$model->validate()) { Yii::$app->response->format = 'json'; return \yii\widgets\ActiveForm::validate($model); } if ($model->save()) { Yii::$app->session->setFlash("success", "Todo excelente!"); } else { Yii::$app->session->setFlash("error", "Todo mal!"); } //return $this->redirect(['view', 'id' => $model->id, 'created_by' => $model->created_by]); return $this->redirect('index'); } else { return $this->render('create', ['model' => $model]); } }