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


PHP Comment::save方法代码示例

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


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

示例1: actionView

 /** 
  * Controller action for viewing a questions.
  * Also provides functionality for creating an answer,
  * adding a comment and voting.
  */
 public function actionView()
 {
     error_reporting(E_ALL);
     ini_set("display_errors", 1);
     $question = Question::model()->findByPk(Yii::app()->request->getParam('id'));
     if (isset($_POST['Answer'])) {
         $answerModel = new Answer();
         $answerModel->attributes = $_POST['Answer'];
         $answerModel->created_by = Yii::app()->user->id;
         $answerModel->post_type = "answer";
         $answerModel->question_id = $question->id;
         if ($answerModel->validate()) {
             $answerModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id)));
         }
     }
     if (isset($_POST['Comment'])) {
         $commentModel = new Comment();
         $commentModel->attributes = $_POST['Comment'];
         $commentModel->created_by = Yii::app()->user->id;
         $commentModel->post_type = "comment";
         $commentModel->question_id = $question->id;
         if ($commentModel->validate()) {
             $commentModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id)));
         }
     }
     // User has just voted on a question
     if (isset($_POST['QuestionVotes'])) {
         $questionVotesModel = new QuestionVotes();
         $questionVotesModel->attributes = $_POST['QuestionVotes'];
         QuestionVotes::model()->castVote($questionVotesModel, $question->id);
     }
     $this->render('view', array('author' => $question->user->id, 'question' => $question, 'answers' => Answer::model()->overview($question->id), 'related' => Question::model()->related($question->id)));
 }
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:40,代码来源:MainController.php

示例2: actionAdd

 public function actionAdd()
 {
     if (Yii::app()->request->isPostRequest && isset($_POST['Comment'])) {
         $redirect = isset($_POST['redirectTo']) ? $_POST['redirectTo'] : Yii::app()->user->returnUrl;
         $comment = new Comment();
         $module = Yii::app()->getModule('comment');
         $comment->setAttributes($_POST['Comment']);
         $comment->status = $module->defaultCommentStatus;
         if (Yii::app()->user->isAuthenticated()) {
             $comment->setAttributes(array('user_id' => Yii::app()->user->getId(), 'name' => Yii::app()->user->getState('nick_name'), 'email' => Yii::app()->user->getState('email')));
             if ($module->autoApprove) {
                 $comment->status = Comment::STATUS_APPROVED;
             }
         }
         if ($comment->save()) {
             if (Yii::app()->request->isAjaxRequest) {
                 Yii::app()->ajax->success(Yii::t('comment', 'Комментарий добавлен!'));
             }
             $message = $comment->status !== Comment::STATUS_APPROVED ? Yii::t('comment', 'Спасибо, Ваш комментарий добавлен и ожидает проверки!') : Yii::t('comment', 'Спасибо, Ваш комментарий добавлен!');
             Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, $message);
             $this->redirect($redirect);
         } else {
             if (Yii::app()->request->isAjaxRequest) {
                 Yii::app()->ajax->failure(Yii::t('comment', 'Комментарий не добавлен!'));
             }
             Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('comment', 'Комментарий не добавлен! Заполните форму корректно!'));
             $this->redirect($redirect);
         }
     }
     throw new CHttpException(404, Yii::t('comment', 'Страница не найдена!'));
 }
开发者ID:RSol,项目名称:yupe,代码行数:31,代码来源:CommentController.php

示例3: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $validation = Validator::make($input, Comment::$rules);
     if ($validation->passes()) {
         $last_comment = Comment::where('user_id', '=', Auth::user()->id)->orderBy('created_at', 'desc')->first();
         $current_date = new DateTime(date("Y-m-d H:i:s"));
         if (empty($last_comment)) {
             $interval = 5;
         } else {
             $interval = $current_date->diff($last_comment->created_at);
             $interval = intval($interval->format('%i'));
         }
         if ($interval >= 3) {
             $this->add_daily_comment_points();
             $comment = new Comment();
             $comment->media_id = $input['media_id'];
             $comment->comment = htmlspecialchars($input['comment']);
             $comment->user_id = Auth::user()->id;
             $comment->save();
             echo $comment;
         } else {
             echo 0;
         }
     } else {
         echo 0;
     }
 }
开发者ID:giangcoffee,项目名称:ninja,代码行数:33,代码来源:CommentsController.php

示例4: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($bookId = null, $seriesId = null)
 {
     $model = new Comment();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Comment'])) {
         $_POST['Comment']['author'] = Yii::app()->user->name;
         $_POST['Comment']['date'] = date('d M Y H:i:s');
         $model->attributes = $_POST['Comment'];
         if ($model->save()) {
             if (isset($bookId)) {
                 $commentsBooks = new CommentsBooks();
                 $commentsBooks->commnet_id = $model->id;
                 $commentsBooks->book_id = $bookId;
                 $commentsBooks->save();
                 $this->redirect(array('book/view/' . $bookId));
             }
             if (isset($seriesId)) {
                 $commentsSeries = new CommentsSeries();
                 $commentsSeries->comment_id = $model->id;
                 $commentsSeries->series_id = $seriesId;
                 $commentsSeries->save();
                 $this->redirect(array('series/view/' . $seriesId));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:evgeny-yakovets,项目名称:book_site,代码行数:32,代码来源:CommentController.php

示例5: actionDoAddComment

 public function actionDoAddComment()
 {
     $mid = $_POST['mid'];
     $id = $_POST['id'];
     $type = $_POST['type'];
     $object_id = $_POST['object_id'];
     $comment = $_POST['comment'];
     $quietly = $_POST['quietly'];
     $toId = $_POST['toId'];
     $model = new Comment();
     $params = array('type' => $type, 'object_id' => $object_id, 'comment' => $comment, 'toId' => $toId, 'quietly' => $quietly);
     $model->attributes = $params;
     $model->save();
     if (!empty($model->errors)) {
         echo -1;
         exit;
     }
     //		$data = $model->attributes;
     //		$data['face']=$model->user->getUserFace();
     //		echo CJSON::encode($data);
     $comment = $model->attributes;
     $comment['face'] = $model->user->getUserFace();
     if (!$comment[toId]) {
         $data['comment'] = $comment;
         $this->renderPartial('comment_li', $data);
     } else {
         $data['subcomment'] = $comment;
         $this->renderPartial('subcomment_li', $data);
     }
 }
开发者ID:vangogogo,项目名称:justsns,代码行数:30,代码来源:CommentController.php

示例6: add_comment

 public function add_comment()
 {
     $record = RegisterRecord::find(Input::get('record_id'));
     if (!isset($record)) {
         return Response::json(array('error_code' => 2, 'message' => '无该记录'));
     }
     $user_id = RegisterAccount::find($record->account_id)->user_id;
     if ($user_id != Session::get('user.id')) {
         return Response::json(array('error_code' => 3, 'message' => '无效记录'));
     }
     if (!Input::has('content')) {
         return Response::json(array('error_code' => 4, 'message' => '请输入评价'));
     }
     $old_comment = $record->comment()->get();
     if (isset($old_comment)) {
         return Response::json(array('error_code' => 5, 'message' => '已评论'));
     }
     $comment = new Comment();
     $comment->record_id = $record->id;
     $comment->content = Input::get('content');
     if (!$comment->save()) {
         return Response::json(array('error_code' => 1, 'message' => '添加失败'));
     }
     return Response::json(array('error_code' => 0, 'message' => '添加成功'));
 }
开发者ID:Jv-Juven,项目名称:hospital-register-system,代码行数:25,代码来源:CommentController.php

示例7: posts

 public function posts($id)
 {
     $this->load->helper('form');
     $this->load->model(['post', 'comment']);
     $post = NULL;
     try {
         $post = Post::findOrFail($id);
     } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         show_404();
     }
     $data = ['menu' => 'blog', 'post' => $post];
     $this->load->library('form_validation');
     $this->form_validation->set_error_delimiters('<p class="text-danger"><strong><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> ', '</strong></p>');
     if ($this->form_validation->run('create-comment') == FALSE) {
         $this->load->view('front/blog-post', $data);
     } else {
         $comment = new Comment();
         $comment->post_id = $this->input->post('id');
         $comment->name = $this->input->post('name');
         $comment->content = $this->input->post('comment');
         $comment->save();
         $this->session->set_flashdata('message', 'Successfully save!');
         redirect('posts/' . $id . '#comments');
     }
 }
开发者ID:harithaakella,项目名称:CS597-Project-Code,代码行数:25,代码来源:Welcome.php

示例8: executeDoAdd

 /**
  * executeDo_add_new_comment 
  * 
  * @access public
  * @return void
  */
 public function executeDoAdd(sfWebRequest $request)
 {
     // Pull associated model
     $record_id = $request->getParameter('record_id');
     $model = $request->getParameter('model');
     $this->record = Doctrine::getTable($model)->find($record_id);
     $commentForm = new CommentForm();
     $commentForm->bind($request->getParameter('comment'));
     // return bound form with errors if form is invalid
     if (!$commentForm->isValid()) {
         return $this->renderPartial('csComments/add_comment', array('commentForm' => $commentForm));
     }
     // save the object
     /* SHOULD USE IMBEDDED FORMS
            Used this hack instead.  Need to fix
            -B.Shaffer
        */
     $commentVals = $commentForm->getValues();
     $commenter = new Commenter();
     $commenter->fromArray($commentVals['Commenter']);
     $commenter->save();
     $comment = new Comment();
     $comment['body'] = $commentVals['body'];
     $comment['Commenter'] = $commenter;
     $comment->save();
     $this->comment = $comment;
     // Pass parent comment id if comment is nested
     $parent_id = $this->getRequestParameter('comment_id');
     $this->record->addComment($this->comment, $parent_id);
     $this->record->save();
 }
开发者ID:bshaffer,项目名称:Symplist,代码行数:37,代码来源:BasecsCommentsActions.class.php

示例9: testCounterIncrementsAndDecrementsWhen

 public function testCounterIncrementsAndDecrementsWhen()
 {
     $post_with_comments = new Post();
     $post_with_comments->title = 'post 1';
     $this->assertTrue($post_with_comments->save());
     $post_without_comments = new Post();
     $post_without_comments->title = 'post 2';
     $this->assertTrue($post_without_comments->save());
     //Create 10 comments, ensure counter increments
     for ($i = 1; $i <= 10; $i++) {
         $comment = new Comment();
         $comment->postId = $post_with_comments->id;
         $comment->text = 'comment ' . $i;
         $this->assertTrue($comment->save());
         $post_with_comments->refresh();
         $post_without_comments->refresh();
         $this->assertEquals($post_with_comments->commentsCount, $i);
         $this->assertEquals($post_without_comments->commentsCount, 0);
     }
     //Delete all comments, ensure counter decrements
     $comments = Comment::find()->all();
     $count = count($comments);
     foreach ($comments as $comment) {
         $this->assertEquals($comment->delete(), 1);
         $count--;
         $post_with_comments->refresh();
         $this->assertEquals($post_with_comments->commentsCount, $count);
     }
 }
开发者ID:ostapetc,项目名称:yii2-cache-counter-behavior,代码行数:29,代码来源:CounterCacheBehaviorTest.php

示例10: postBlogComment

 /**
  * 提交评论
  * @param  string $slug 文章缩略名
  * @return response
  */
 public function postBlogComment($slug)
 {
     // 获取评论内容
     $content = e(Input::get('content'));
     // 字数检查
     if (mb_strlen($content) < 3) {
         return Redirect::back()->withInput()->withErrors($this->messages->add('content', '评论不得少于3个字符。'));
     }
     // 查找对应文章
     $article = Article::where('slug', $slug)->first();
     // 创建文章评论
     $comment = new Comment();
     $comment->content = $content;
     $comment->article_id = $article->id;
     $comment->user_id = Auth::user()->id;
     if ($comment->save()) {
         // 创建成功
         // 更新评论数
         $article->comments_count = $article->comments->count();
         $article->save();
         // 返回成功信息
         return Redirect::back()->with('success', '评论成功。');
     } else {
         // 创建失败
         return Redirect::back()->withInput()->with('error', '评论失败。');
     }
 }
开发者ID:ningcaichen,项目名称:laravel-4.1-simple-blog,代码行数:32,代码来源:BlogController.php

示例11: saveComment

 public static function saveComment($userId)
 {
     $comment = new Comment();
     $comment->text = $_POST['text'];
     $comment->user_id = $userId;
     $comment->save();
 }
开发者ID:AJIACTOP,项目名称:MVC-Framework,代码行数:7,代码来源:Comment.php

示例12: post

 public function post()
 {
     // Only permit logged in users to comment
     if (Auth::check()) {
         // Add a rule to verify the particular item exists
         Validator::extend('itemExists', function ($attribute, $value, $parameters) {
             $type = ucfirst(Input::get('type'));
             $item = $type::find($value);
             return $item;
         });
         // Validate the data
         $validator = Validator::make(Input::all(), array('id' => 'itemExists', 'type' => 'in:doctor,companion,enemy,episode', 'title' => 'required|min:5', 'email' => 'required|email', 'content' => 'required'), array('required' => 'You forgot to include the :attribute on your comment!', 'itemExists' => 'If you can see this, the universe is broken because that ' . Input::get('type') . ' does not exist.'));
         if ($validator->fails()) {
             return Redirect::to(URL::previous() . '#comments')->withErrors($validator)->withInput();
         } else {
             $comment = new Comment();
             $comment->user_id = Auth::id();
             $comment->item_id = Input::get('id');
             $comment->item_type = Input::get('type');
             $comment->title = Input::get('title');
             $comment->content = Input::get('content');
             $comment->save();
             return Redirect::to(URL::previous() . '#comments')->with('message', 'Comment posted');
         }
     }
 }
开发者ID:thechrisroberts,项目名称:thedoctor,代码行数:26,代码来源:CommentController.php

示例13: processRequest

 /**
  * @param $model
  * @return Comment
  */
 public function processRequest($model)
 {
     $comment = new Comment();
     if (Yii::app()->request->isPostRequest) {
         $comment->attributes = Yii::app()->request->getPost('Comment');
         if (!Yii::app()->user->isGuest) {
             $comment->name = Yii::app()->user->name;
             $comment->email = Yii::app()->user->email;
         }
         if ($comment->validate()) {
             $pkAttr = $model->getObjectPkAttribute();
             $comment->class_name = $model->getClassName();
             $comment->object_pk = $model->{$pkAttr};
             $comment->user_id = Yii::app()->user->isGuest ? 0 : Yii::app()->user->id;
             $comment->save();
             $url = Yii::app()->getRequest()->getUrl();
             if ($comment->status == Comment::STATUS_WAITING) {
                 $url .= '#';
                 Yii::app()->user->setFlash('messages', Yii::t('CommentsModule.core', 'Ваш комментарий успешно добавлен. Он будет опубликован после проверки администратором.'));
             } elseif ($comment->status == Comment::STATUS_APPROVED) {
                 $url .= '#comment_' . $comment->id;
             }
             // Refresh page
             Yii::app()->request->redirect($url, true);
         }
     }
     return $comment;
 }
开发者ID:kolbensky,项目名称:rybolove,代码行数:32,代码来源:CommentsModule.php

示例14: actionView

 public function actionView()
 {
     if (!isset($_GET['id'])) {
         throw new CHttpException(404, 'Страница не найденa');
     } else {
         $site_id = $_GET['id'];
         $site = Site::model()->findByPk($site_id);
         if ($site == null) {
             throw new CHttpException(404, 'Страница не найденa');
         } else {
             $value = '';
             if (!Yii::app()->user->isGuest) {
                 $mark = Mark::model()->find('site_id = :site_id AND user_id = :user_id', array('site_id' => $site->site_id, 'user_id' => Yii::app()->user->id));
                 if ($mark != null) {
                     $value = $mark->value;
                 }
                 if ($_POST) {
                     $comment = new Comment();
                     $comment->attributes = $_POST['Comment'];
                     $comment->user_id = Yii::app()->user->id;
                     $comment->site_id = $site->site_id;
                     $comment->date = date('Y-m-d H:i:s');
                     $comment->save();
                     $this->redirect(array('view', 'id' => $site->site_id));
                 }
             }
             $this->render('view', array('site' => $site, 'value' => $value));
         }
     }
 }
开发者ID:GKillah,项目名称:social,代码行数:30,代码来源:SiteController.php

示例15: testSaveWithIdShouldReturnTrue

 /**
  * Test
  *
  * @return void
  */
 public function testSaveWithIdShouldReturnTrue()
 {
     $this->object->setContent('test');
     $this->object->setTemplateId(1);
     $this->object->save();
     $this->assertTrue($this->object->save());
     $this->object->delete();
 }
开发者ID:gotcms,项目名称:gotcms,代码行数:13,代码来源:ModelTest.php


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