/** * Store a newly created Comentario in storage. * * @param CreateComentarioRequest $request * * @return Response */ public function store() { $input = Request::all(); $Comentario = Comentario::create($input); $data = Request::all(); $data['success'] = true; return json_encode($data); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comentario::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, 'noticia_id' => $this->noticia_id]); $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'correo', $this->correo])->andFilterWhere(['like', 'comentario', $this->comentario])->andFilterWhere(['like', 'estado', $this->estado]); return $dataProvider; }
public function search($input) { $query = Comentario::query(); $columns = Schema::getColumnListing('Comentarios'); $attributes = array(); foreach ($columns as $attribute) { if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } else { $attributes[$attribute] = null; } } return [$query->get(), $attributes]; }
public function getTotalComentarios() { return $this->hasMany(Comentario::className(), ['noticia_id' => 'id'])->where('estado = 1')->count('id'); }
/** * Finds the Comentario model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Comentario the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Comentario::findOne(['id' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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]); }