Exemple #1
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, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'titulo', $this->titulo])->andFilterWhere(['like', 'seo_slug', $this->seo_slug])->andFilterWhere(['like', 'detalle', $this->detalle]);
     return $dataProvider;
 }
Exemple #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getNoticias()
 {
     return $this->hasMany(Noticia::className(), ['categoria_id' => 'id']);
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getNoticia()
 {
     return $this->hasOne(Noticia::className(), ['id' => 'noticia_id']);
 }
Exemple #4
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]);
 }
 /**
  * Finds the Noticia model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @param integer $created_by
  * @return Noticia the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id, $created_by)
 {
     if (($model = Noticia::findOne(['id' => $id, 'created_by' => $created_by])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }