/** * Creates a new Comments model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Comments(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(CommentsRequest $request) { $comment = new Comments(); $comment->text = $request->text; $comment->ads_id = $request->ads_id; $comment->user_id = Auth::user()->id; $comment->save(); Event::fire(new CreateComment($request->type, $request->ads_id, $request->user_id, $comment->id)); return \Redirect::to('/ads/' . $request->ads_id); }
public function postComment(CommentsCreateRequest $req) { $comment = new Comments(); $comment->comment = $req->input('comment'); $comment->status = 1; $comment->diary_id = $req->input('diary_id'); $comment->user_id = Auth::user()->id; if ($comment->save()) { return redirect('diary/read/' . $req->input('diary_id') . '#comment')->with('msg', 'Successfully comment posted'); } }
/** * Creates a new Comments model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($id_item = null) { $model = new Comments(); if ($model->load(Yii::$app->request->post())) { //var_dump($model->id_item); exit(); $model->id_item = $id_item; if ($model->save()) { return $this->redirect(['items/view', 'id' => $id_item]); } } else { return $this->render('create', ['model' => $model]); } }
/** * Displays a single Post model. * Also added functionality of adding comments, related to particular Post model. * @param integer $id * @return mixed */ public function actionView($id) { $comments = Comments::find()->where(['post_id' => $id])->all(); $newComment = new Comments(); if ($newComment->load(Yii::$app->request->post()) && $newComment->validate()) { $newComment->created_at = time(); $newComment->post_id = $id; $newComment->save(); return $this->redirect(['view', 'id' => $id]); } else { return $this->render('view', ['model' => $this->findModel($id), 'comments' => $comments, 'newComment' => $newComment]); } }
public function actionAddComment() { $comment = Yii::$app->request->post(); $model = new Comments(); $model->article_id = $comment['article']; $model->user_id = $comment['user']; $model->comment = $comment['comment']; $model->enable = 1; $model->save(); $user = Comments::find()->with('user')->where(['id' => $model->id])->one(); $array = array('comment' => $model->comment, 'user' => $user->user->name_fml); echo json_encode($array); // print_r($user->user->name_fml); }
public function actionProduct($id = null) { $product = Products::find()->where(['id' => $id])->one(); $sec = Sections::find(['title'])->where(['id' => $product->section_id])->one(); $others = Products::find()->orderBy(['date' => SORT_DESC])->where(['section_id' => $product->section_id])->andWhere(['not in', 'id', [$id]])->limit(4)->all(); $comments = Comments::find()->where(['product_id' => $id])->orderBy(['id' => SORT_DESC])->all(); $model = new CommentForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $com = new Comments(); $com->product_id = $id; $com->login = Yii::$app->session->get('login'); $com->comment = $model->comment; $com->save(); return $this->redirect(Yii::$app->request->referrer); } return $this->render('product', ['product' => $product, 'section_title' => $sec, 'others' => $others, 'model' => $model, 'comments' => $comments]); }
public function actionCreate() { if (Yii::$app->getRequest()->getQueryParam('name')) { var_dump(Yii::$app->getRequest()->getQueryParam('host')); } else { echo 'no_name'; } if (Yii::$app->getRequest()->getQueryParam('body')) { var_dump(Yii::$app->getRequest()->getQueryParam('body')); } else { echo 'no_body'; } $model = new Comments(); if ($model->load(Yii::$app->request->post())) { $model->name = Yii::$app->request->post('Comments')['name']; $model->body = Yii::$app->request->post('Comments')['body']; $model->save(); } }
function run() { // && $model->contact(Yii::$app->params['adminEmail']) $this->enable_form = $this->allow_comments(); $comment = new Comments(); $comment->parent_id = 0; if ($this->enable_form && $comment->load(Yii::$app->request->post()) && $comment->validate()) { Yii::$app->session->setFlash('commentFormSubmitted'); $comment->active = true; $comment->user_id = Yii::$app->user->isGuest ? null : Yii::$app->user->identity->id; $comment->ip = ip2long(Yii::$app->request->getUserIP()); $comment->agent = Yii::$app->request->getUserAgent(); $comment->saveUploadedImage('file'); $comment->save(); return Yii::$app->getResponse()->redirect(Yii::$app->getRequest()->getUrl()); } $query = new Query(); $query->addSelect('c.*, f.filename, f.thumb_filename, f.size, u.username')->from([Comments::tableName() . ' c'])->leftJoin(User::tableName() . ' u', 'u.id = c.user_id')->leftJoin(Files::tableName() . ' f', 'f.id = c.image_id')->where(['c.active' => true])->andWhere(['c.post_id' => $this->post_id]); $comment->post_id = $this->post_id; return $this->render('comments/comments_box', ['comments' => $this->buildTree($query->all()), 'model' => $comment, 'enable' => $this->enable_form]); }
/** * Displays a grid containing all Objects of this API. * @param integer $id * @param boolean $propose * @param boolean $followed * @param boolean $followersNotified * @return mixed */ public function actionView($id, $propose = false, $followed = null, $followersNotified = null) { $searchModel = new ObjectsSearch(); $dataProvider = $searchModel->search(['ObjectsSearch' => ['api' => $id]]); $commentSearchModel = new CommentsSearch(); $commentsProvider = $commentSearchModel->findCommentsNotReplies(['CommentsSearch' => ['api' => $id]]); $repliesProvider = $commentSearchModel->findReplies(['CommentsSearch' => ['api' => $id]]); $repliesProvider->setPagination(false); $commentsModel = new Comments(); $commentsModel->api = $id; if ($commentsModel->load(Yii::$app->request->post())) { $commentsModel->save(); } $myId = \Yii::$app->user->id; $followUserAPI = FollowUserApi::findOne(['follower' => $myId, 'api' => $id]); $doIFollow = false; if ($followUserAPI) { $doIFollow = true; $followUserAPI->last_seen = date('Y-m-d H:i:s'); $followUserAPI->changed_name = false; $followUserAPI->changed_descr = false; $followUserAPI->changed_version = false; $followUserAPI->changed_proposed = false; $followUserAPI->changed_published = false; $followUserAPI->changed_privacy = false; $followUserAPI->changed_upvotes = 0; $followUserAPI->changed_downvotes = 0; $followUserAPI->changed_objects_number = 0; $followUserAPI->save(); } $followers = FollowUserApi::find()->where(['api' => $id])->count(); $this->view->params['followers_notified'] = $followersNotified; $this->view->params['propose'] = $propose; $this->view->params['followed'] = $followed; // Elastic Search Query for Recommendations $esq = new ElasticSearchQuery(); $api = $this->findModel($id); $esq->setApi($api); $esq->MakeJSON(); $recommend = $esq->Build(); return $this->render('view', ['model' => $this->findModel($id), 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'doIFollow' => $doIFollow, 'followers' => $followers, 'commentsProvider' => $commentsProvider, 'repliesProvider' => $repliesProvider, 'commentsModel' => $commentsModel, 'recommend' => $recommend]); }
public function save_comments(Request $request) { $comments = new Comments(); $comments->blog_id = $request->blog_id; $comments->user_author_name = Session::get('name'); $comments->blog_comments = $request->blog_comments; $comments->save(); Session::put('message', 'Your Comments Save Successfully And Weating For Admin Approval !'); return redirect('/blog-details/' . $request->blog_id); }
/** * Добавление комментариев * @return string */ public function actionAddcomment() { $model = new Comments(); $model->body = Yii::$app->request->post('Comments')['body']; if (Yii::$app->getRequest()->getQueryParam('name')) { $model->name = Yii::$app->getRequest()->getQueryParam('name'); } if (Yii::$app->getRequest()->getQueryParam('body')) { $model->body = Yii::$app->getRequest()->getQueryParam('body'); } if (Yii::$app->getRequest()->getQueryParam('content_id')) { self::$content_id = $model->article_content_id = (int) Yii::$app->getRequest()->getQueryParam('content_id'); } $model->status = 'published'; if ($model->save(false)) { return "<script>\n if(\$.cookie('name')) \$('.field-comments-name').html( 'Привет, ' + \$.cookie('name'));\n\n </script><p style='color: green'>Ответ опубликован</p>"; } return "<p style='color: red'>Попробуйте ещё раз чуть позже</p>"; }
public function actionSavecomment() { $model = new Comments(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['site/detailpost', 'id' => $model->post_id]); } else { return $this->redirect('index.php'); } }
public function actionAddcomment($name, $email, $comment, $product_id) { $model = new Comments(); $model->name = $name; $model->email = $email; $model->comment = $comment; $model->product_id = $product_id; if ($model->save()) { return 'success'; } return 'fail'; }