/**
  * 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()->where("seo_slug = :slug", [":slug" => $slug])->orderBy('id')->one();
     /*
             CONSULTA DE LOS COMENTARIOS DESDE EL CONTROLADOR
     
        $idNoticia=$noticia->id;
         $comentarios= Comentario::find()
         ->where("noticia_id = :idNoticia", [":idNoticia" => $idNoticia])
         ->all();
     */
     $comentario = new Comentario();
     if ($comentario->load(Yii::$app->request->post())) {
         $comentario->estado = '0';
         $comentario->noticia_id = $noticia->id;
         $comentario->fecha = new Expression("NOW()");
         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]);
 }