/**
  * Creates a new Comentario model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Comentario();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Beispiel #2
0
 public function actionNoticia($slug)
 {
     $categorias = Categoria::find()->all();
     $noticia = Noticia::find("seo_slug = :slug", [":slug" => $slug])->one();
     $comentario = new Comentario(["scenario" => "comentario"]);
     if ($comentario->load(Yii::$app->request->post())) {
         $comentario->estado = '0';
         $comentario->noticia_id = $noticia->id;
         $comentario->fecha = new Expression("NOW()");
         $comentario->correo = Security::mcrypt($comentario->correo);
         if ($comentario->save()) {
             Yii::$app->session->setFlash('success', 'Gracias por su comentario');
         } else {
             Yii::$app->session->setFlash('error', 'Su comentario no pudo ser registrado');
         }
         return $this->redirect(["/noticia/{$slug}"]);
     }
     return $this->render('noticia', ['comentario' => $comentario, 'categorias' => $categorias, 'noticia' => $noticia]);
 }