/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Noticia::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id_noticia' => $this->id_noticia, 'importante' => $this->importante, 'fecha' => $this->fecha]);
     $query->andFilterWhere(['like', 'titulo', $this->titulo])->andFilterWhere(['like', 'descripcion', $this->descripcion]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Noticia::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'categoria_id' => $this->categoria_id, 'created_by' => $this->created_by, 'created_at' => $this->created_at, 'udated_by' => $this->udated_by, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'titulo', $this->titulo])->andFilterWhere(['like', 'detalle', $this->detalle]);
     return $dataProvider;
 }
Exemplo n.º 3
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]);
 }