當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Comment::load方法代碼示例

本文整理匯總了PHP中common\models\Comment::load方法的典型用法代碼示例。如果您正苦於以下問題:PHP Comment::load方法的具體用法?PHP Comment::load怎麽用?PHP Comment::load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common\models\Comment的用法示例。


在下文中一共展示了Comment::load方法的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()
 {
     if (\Yii::$app->request->isAjax) {
         $model = new Comment();
         if (\Yii::$app->user->isGuest) {
             $model->scenario = 'isGuest';
         }
         $data = ['error' => true];
         if ($model->load(\Yii::$app->request->post())) {
             $parentID = \Yii::$app->request->post('parent_id');
             $root = $model->makeRootIfNotExist();
             if (!$parentID) {
                 $model->appendTo($root);
             } else {
                 $parent = Comment::find()->where(['id' => $parentID])->one();
                 $model->appendTo($parent);
             }
             $articleModel = Article::findOne($model->model_id);
             $data = ['replaces' => [['what' => '#comments', 'data' => $this->renderAjax('@app/themes/basic/modules/article/views/default/_comments', ['model' => $articleModel])]]];
         }
         return Json::encode($data);
     } else {
         throw new NotFoundHttpException(\Yii::t('app', 'Page not found'));
     }
 }
開發者ID:tolik505,項目名稱:bl,代碼行數:25,代碼來源:DefaultController.php

示例3: 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

示例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()
 {
     $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

示例5: 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

示例6: 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

示例7: 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

示例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: 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

示例11: 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

示例12: 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

示例13: 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

示例14: actionAdd

 public function actionAdd()
 {
     if (User::thisUser()->reputation < Comment::MIN_REPUTATION_COMMENT_CREATE) {
         return Yii::$app->getResponse()->redirect(Url::home());
     }
     $anchor = '';
     $comment = new Comment();
     if ($comment->load(Yii::$app->request->post())) {
         $comment->description = nl2br($comment->description);
         $comment->description = \yii\helpers\HtmlPurifier::process($comment->description, []);
         $comment->entity_id = (int) $comment->entity_id;
         $comment->parent_id = (int) $comment->parent_id;
         $comment->user_id = Yii::$app->user->identity->getId();
         $comment->like_count = 0;
         if ($comment->save()) {
             $anchor = $comment->id;
         }
     }
     return json_encode(['content' => \frontend\widgets\CommentsWidget::widget(['entity' => $comment->entity, 'entity_id' => $comment->entity_id, 'showDialog' => false]), 'anchor' => $anchor]);
 }
開發者ID:IVsevolod,項目名稱:zouk,代碼行數:20,代碼來源:CommentController.php

示例15: actionNewComment

 public function actionNewComment()
 {
     if ($this->isAjax()) {
         $model = new Comment();
         $model->load($this->getParams());
         $validate = $model->validate();
         $reCaptcha = new ReCaptcha();
         $response = $reCaptcha->check();
         if ($validate && $response->isValid() && $model->save(false)) {
             return $this->getSuccessResponse(['email' => $model->email, 'text' => $model->text]);
         } else {
             $res = [];
             if (!$validate) {
                 $res['modelErrors'] = ActiveForm::validate($model);
             }
             if (!$response->isValid()) {
                 $res['reCaptchaError'] = true;
             }
             return $res;
         }
     }
     return Yii::$app->params['response']['error'];
 }
開發者ID:Zhanat87,項目名稱:alina.test,代碼行數:23,代碼來源:SiteController.php


注:本文中的common\models\Comment::load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。