当前位置: 首页>>代码示例>>PHP>>正文


PHP Comment::save方法代码示例

本文整理汇总了PHP中common\models\Comment::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::save方法的具体用法?PHP Comment::save怎么用?PHP Comment::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\Comment的用法示例。


在下文中一共展示了Comment::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * Creates a new Comment model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new Comment();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['code' => '200', 'message' => 'OK', 'data' => $this->renderPartial('create', ['model' => $model])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['code' => '200', 'message' => 'Create Comment success'];
             } else {
                 return ['code' => '400', 'message' => 'Validate error', 'data' => $this->renderPartial('create', ['model' => $model])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
开发者ID:hdushku,项目名称:npai,代码行数:35,代码来源:CommentController.php

示例2: actionAddComment

 public function actionAddComment()
 {
     $comment = new Comment();
     $comment->load(Yii::$app->request->post(), '');
     if ($comment->save()) {
         return $comment;
     }
     return $comment->getErrors();
 }
开发者ID:bolom009,项目名称:testwork_api,代码行数:9,代码来源:CommentController.php

示例3: actionCreate

 /**
  * Creates a new Comment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Comment();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:ilhammalik,项目名称:yii2-starter,代码行数:14,代码来源:CommentController.php

示例4: actionCreate

 /**
  * Creates a new Comment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //if(!Yii::$app->user->can('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $model = new Comment();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:CTaiDeng,项目名称:funshop,代码行数:16,代码来源:CommentController.php

示例5: actionComment

 public function actionComment($id)
 {
     $model = new Comment();
     $model->load(Yii::$app->request->post());
     $model->article_id = $id;
     if ($model->validate()) {
         $model->save();
         Yii::$app->session->setFlash("success", "Ок");
     }
     $this->redirect(["article/view", "id" => $id]);
 }
开发者ID:horechek,项目名称:nnews,代码行数:11,代码来源:ArticleController.php

示例6: actionView

 public function actionView($slug)
 {
     $commentForm = new Comment();
     if ($commentForm->load(Yii::$app->request->post())) {
         if ($commentForm->save()) {
             Yii::$app->session->setFlash('success', '评论发表成功');
         } else {
             Yii::$app->session->setFlash('error', '评论发表失败');
         }
     }
     return $this->render('view', ['article' => Page::getInstance()->getBySlug($slug), 'commentForm' => $commentForm]);
 }
开发者ID:luobenyu,项目名称:blog-1,代码行数:12,代码来源:PageController.php

示例7: save

 /**
  * 保存商品
  */
 public function save()
 {
     $newComent = new Comment();
     $newComent->setAttributes($this->attributes);
     $newComent->setAttribute('c_type', 'article');
     $newComent->setAttribute("c_addtime", date('Y-m-d H:i:s'));
     if ($newComent->save()) {
         $logisct_id = \Yii::$app->db->lastInsertID;
         return $logisct_id;
     } else {
         return FALSE;
     }
 }
开发者ID:wxzuan,项目名称:wxzuan,代码行数:16,代码来源:SayingForm.php

示例8: actionCreate

 public function actionCreate()
 {
     $model = new Comment();
     $model->load(\Yii::$app->request->post());
     $model->user_id = \Yii::$app->user->id;
     $returnUrl = \Yii::$app->request->getReferrer();
     if ($model->save()) {
         \Yii::$app->session->setFlash('success', '评论成功!');
     } else {
         \Yii::$app->session->setFlash('error', '评论失败!');
     }
     return $this->redirect($returnUrl);
 }
开发者ID:zhangsong,项目名称:yii,代码行数:13,代码来源:CommentController.php

示例9: actionIndex

 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $model = new Comment();
     if ($model->load(Yii::$app->request->post())) {
         $model->is_active = 0;
         $model->created_at = date('Y-m-d H:i:s');
         $model->updated_at = date('Y-m-d H:i:s');
         $model->save();
         Yii::$app->session->setFlash('success', 'Thank you! Your comment has been added successfully. It will be available after moderation ;)');
         return $this->redirect('/');
     }
     return $this->render('comments', ['model' => $model]);
 }
开发者ID:roman-gich,项目名称:comments,代码行数:18,代码来源:SiteController.php

示例10: actionAddComment

 public function actionAddComment()
 {
     $productId = Yii::$app->request->post('productId');
     $rank = Yii::$app->request->post('rank');
     $content = Yii::$app->request->post('content');
     $comment = new Comment();
     $comment->attributes = ['product_id' => $productId, 'user_id' => Yii::$app->user->identity->id, 'rank' => $rank, 'content' => $content];
     if ($comment->save(true)) {
         return ['status' => true, 'message' => '成功'];
     } else {
         return ['status' => false, 'message' => '失败: ' . Html::errorSummary($comment)];
     }
 }
开发者ID:su-xiaolin,项目名称:ICShop-Yii,代码行数:13,代码来源:ProductController.php

示例11: actionCreate

 /**
  * Creates a new Comment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionCreate()
 {
     $model = new Comment();
     if (Yii::$app->request->isGet) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $model->author_id = Yii::$app->user->id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['../post/view', 'id' => $model->post_id]);
     } else {
         return $this->render('../post/view', ['model' => Post::findOne($model->post_id)]);
     }
 }
开发者ID:viktornord,项目名称:gh-php-blog,代码行数:19,代码来源:CommentController.php

示例12: actionView

 /**
  * Displays a single Post model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $list_comment = new ActiveDataProvider(['query' => Comment::find()->where(['post_id' => $id, 'status' => 1])]);
     $model_comment = new Comment();
     if ($model_comment->load(Yii::$app->request->post())) {
         $model_comment->post_id = $id;
         $model_comment->status = 0;
         if ($model_comment->save()) {
             Yii::$app->session->setFlash('success', 'Ваш комментарий был отправлен администраторам сайта и будет опубликован после проверки..');
         } else {
             Yii::$app->session->setFlash('error', 'Ваш комментарий не был отправлен по техническим причинам. Попробуйте ещё раз.');
         }
     }
     return $this->render('view', ['model' => $this->findModel($id), 'list_comment' => $list_comment, 'model_comment' => $model_comment]);
 }
开发者ID:kuzma17,项目名称:paveldent,代码行数:20,代码来源:PostController.php

示例13: actionView

 public function actionView($slug)
 {
     $post = Post::findOne(['slug' => $slug]);
     $comment = new Comment();
     $comment->name = '';
     $comment->email = '';
     $comment->body = '';
     if ($comment->load(Yii::$app->request->post())) {
         $comment->status = 0;
         if ($comment->save()) {
             Yii::$app->session->setFlash('success', ['type' => 'success', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'You\'re comment successfully stored and will shown after approval.', 'title' => 'Saving Comment']);
         } else {
             Yii::$app->session->setFlash('error', ['type' => 'danger', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'Sorry but we couldn\'t store your comment.', 'title' => 'Saving Comment']);
         }
     }
     return $this->render('view', ['post' => $post, 'comment' => $comment]);
 }
开发者ID:ninjacto,项目名称:ninjacto.com,代码行数:17,代码来源:BlogController.php

示例14: actionAddComment

 /**
  * @return array
  * Добавление комментария
  */
 public function actionAddComment()
 {
     if (\Yii::$app->request->isAjax) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         $model = new Comment();
         $model->user_id = \Yii::$app->user->identity->id;
         $model->event_id = $_POST['event_id'];
         $model->message = $_POST['message'];
         $model->created = time();
         if ($model->save()) {
             if (isset($_POST['notify_all']) && $_POST['notify_all'] == 'true') {
                 EventForm::commenatAllNotification($_POST['event_id'], $_POST['message']);
             }
             return ['item' => $model, 'user' => $model->user];
         }
     }
 }
开发者ID:KPEMATOP,项目名称:findspree_old,代码行数:21,代码来源:CommentController.php

示例15: actionDetail

 public function actionDetail($id)
 {
     $postModel = new Comment();
     if ($postModel->load(Yii::$app->request->post())) {
         $postModel->status = Comment::STATUS_INACTIVE;
         $postModel->post_id = $id;
         if ($postModel->save()) {
             $this->added = 1;
         }
     }
     $tags = Tag::findTagWeights();
     $cateModel = new Cate();
     $cateDataProvider = $cateModel->getCates();
     $postData = new Post();
     $postDataProvider = $postData->findRecentPosts();
     $commentModel = new Comment();
     $commentDataProvider = $commentModel->findRecentComments();
     return $this->render('detail', ['tags' => $tags, 'added' => $this->added, 'postModel' => $postModel, 'model' => $this->findModel($id), 'postDataProvider' => $postDataProvider, 'cateDataProvider' => $cateDataProvider, 'commentDataProvider' => $commentDataProvider]);
 }
开发者ID:whystic,项目名称:yii2-whystic-blog,代码行数:19,代码来源:HomeController.php


注:本文中的common\models\Comment::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。