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


PHP Comment::validate方法代码示例

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


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

示例1: postView

 /**
  * View a blog post.
  *
  * @param  string   $slug
  * @return Redirect
  */
 public function postView($slug)
 {
     // The user needs to be logged in, make that check please
     if (!Sentry::check()) {
         return Redirect::to("blog/{$slug}#comments")->with('error', Lang::get('post.messages.login'));
     }
     // Get this blog post data
     $post = $this->post->where('slug', $slug)->first();
     // get the  data
     $new = Input::all();
     $comment = new Comment();
     // If validation fails, we'll exit the operation now
     if ($comment->validate($new)) {
         // Save the comment
         $comment->user_id = Sentry::getUser()->id;
         $comment->content = e(Input::get('comment'));
         // Was the comment saved with success?
         if ($post->comments()->save($comment)) {
             // Redirect to this blog post page
             return Redirect::to("blog/{$slug}#comments")->with('success', 'Your comment was successfully added.');
         }
     } else {
         // failure, get errors
         return Redirect::to("blog/{$slug}#comments")->withInput()->withErrors($comment->errors());
     }
     // Redirect to this blog post page
     return Redirect::to("blog/{$slug}#comments")->with('error', Lang::get('post.messages.generic'));
 }
开发者ID:jeremiteki,项目名称:mteja-laravel,代码行数:34,代码来源:PostController.php

示例2: postComment

 public function postComment($id)
 {
     $input = Input::all();
     Log::info($input);
     $validator = Comment::validate($input);
     if ($validator->fails()) {
         FlashHelper::message("Null title", FlashHelper::DANGER);
         return;
     }
     $post = Post::findOrFail($id);
     if (!$post->can_comment || !PrivacyHelper::checkPermission(Auth::user(), $post)) {
         throw new Exception("Don't have permision");
     }
     $comment = new Comment();
     $Parsedown = new Parsedown();
     $comment->post_id = $id;
     $comment->parrent_id = $input['parrent_id'];
     $comment->markdown = $input['markdown'];
     Log::info($comment);
     $comment->HTML = $Parsedown->text($comment->markdown);
     $comment->save();
     $comment->comments = array();
     $data['html'] = View::make('posts._comment')->with('data', $comment)->with('level', count($comment->parents()))->with('can_comment', true)->render();
     $data['status'] = true;
     $data['parent_id'] = $comment->parrent_id;
     return Response::json($data);
 }
开发者ID:sh1nu11bi,项目名称:CloMa,代码行数:27,代码来源:CommentController.php

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

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

示例5: processRequest

	/**
	 * @param $model
	 * @return Comment
	 */
	public function processRequest($model)
	{
        Yii::import('application.modules.users.models.User');
        Yii::import('application.modules.catalog.models.Orgs');
		$comment = new Comment;
		if(Yii::app()->request->getPost('Comment'))
		{
			$comment->attributes = Yii::app()->request->getPost('Comment');
			$ratingAjax = null;
			if(isset($_POST['Comment']['rating'])){
				$ratingAjax = (int)$_POST['Comment']['rating'];
				if($ratingAjax == 0) $ratingAjax = null;
			}
			$comment->rating = $ratingAjax;

			if(!Yii::app()->user->isGuest)
			{
				$comment->name = Yii::app()->user->username;
				$comment->email = Yii::app()->user->email;
			}
			
			$comment->status = Comment::STATUS_WAITING;
			if($comment->validate())
			{
				// $pkAttr = $model->getObjectPkAttribute();
				// $comment->class_name = $model->getClassName();
				$comment->object_pk = $model->id;
				$comment->user_id = Yii::app()->user->isGuest ? 0 : Yii::app()->user->id;
				if(!$comment->save()){
					// VarDumper::dump($comment->errors); die(); // Ctrl + X  Delete line
				}

				$url = Yii::app()->getRequest()->getUrl();
			//	if($comment->rating) {
			//		$this->starRating($comment->object_pk, $comment->rating);
			//	}
				

				if($comment->status==Comment::STATUS_WAITING)
				{
					$url.='#';
					Yii::app()->user->setFlash('messages', 'Ваш комментарий успешно добавлен. ');
              
				} elseif($comment->status==Comment::STATUS_APPROVED){
					$url.='#comment_'.$comment->id;
				}
               
	                if(Yii::app()->request->isAjaxRequest){
	                	echo '[]';
	                	Yii::app()->end();
	                } else {
					// Refresh page
					Yii::app()->request->redirect($url, true);
					}
			} 
		}
		return $comment;
	}
开发者ID:Aplay,项目名称:Fastreview_site,代码行数:62,代码来源:CommentsModule.php

示例6: write

 /**
  * To add comments into a particular thread
  * @param $comment
  **/
 public function write(Comment $comment)
 {
     if (!$comment->validate()) {
         throw new ValidationException('invalid comment');
     }
     $db = DB::conn();
     $params = array('thread_id' => $this->id, 'username' => $comment->username, 'body' => $comment->body);
     $db->insert('comment', $params);
 }
开发者ID:LowellaMercurio,项目名称:board-1,代码行数:13,代码来源:thread.php

示例7: post_add

 public function post_add()
 {
     $id = Input::get('id');
     //Find the id of the post
     $post = Post::find($id);
     $validation = Comment::validate(Input::all());
     if ($validation->fails()) {
         return Redirect::to_route('post_view', $post->slug)->with_errors($validation)->with_input();
     } else {
         Comment::create(array('user' => Input::get('user'), 'post_id' => Input::get('id'), 'comment_msg' => Input::get('comment_msg')));
         return Redirect::to_route('post_view', $post->slug)->with('message', 'Comment Posted successfully!');
     }
 }
开发者ID:reeceballano,项目名称:Mayaten-Blog,代码行数:13,代码来源:comments.php

示例8: create

 /**
  * create new thread
  * @param Comment $comment
  * @throws ValidationException
  */
 public function create(Comment $comment)
 {
     $this->validate();
     $comment->validate();
     if ($this->hasError() || $comment->hasError()) {
         throw new ValidationException('invalid thread or comment');
     }
     $db = DB::conn();
     $db->begin();
     $db->query('INSERT INTO thread SET title = ?, created = NOW()', array($this->title));
     $this->id = $db->lastInsertId();
     // write first comment at the same time
     $this->write($comment);
     $db->commit();
 }
开发者ID:ry-htr,项目名称:dietcake-sample,代码行数:20,代码来源:thread.php

示例9: edit

 public function edit(Comment &$comment)
 {
     $this->validate();
     $comment->validate();
     if ($this->hasError() || $comment->hasError()) {
         throw new ValidationException('Invalid thread or comment.');
     }
     $db = DB::conn();
     $db->begin();
     try {
         $db->query("UPDATE thread SET title=?, category_name=?,\n                last_modified=NOW() WHERE id=?", array($this->title, $this->category, $this->id));
         $comment->edit();
         $db->commit();
     } catch (PDOException $e) {
         $db->rollback();
     }
 }
开发者ID:renzosunico,项目名称:MyClassroom,代码行数:17,代码来源:thread.php

示例10: actionCreate

 public function actionCreate()
 {
     if (Yii::app()->user->isGuest) {
         $this->forbidden();
     }
     if (!isset($_POST['Comment'])) {
         $this->badRequest();
     }
     $comment = new Comment(ActiveRecord::SCENARIO_CREATE);
     $comment->attributes = $_POST['Comment'];
     if ($comment->validate()) {
         if (isset($_POST['Comment']['parent_id']) && is_numeric($_POST['Comment']['parent_id'])) {
             $root = Comment::model()->findByPk($_POST['Comment']['parent_id']);
             $comment->appendTo($root);
         } else {
             $comment->saveNode();
         }
     }
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:19,代码来源:CommentController.php

示例11: create

 /** 
  * Validate first the Thread & Comment.
  * If both hasError() -> throw Exception
  * Get title of Thread, Get Comment
  * Insert to the Database.
  * @param $comment
  */
 public function create(Comment $comment)
 {
     $this->validate();
     $comment->validate();
     if ($this->hasError() || $comment->hasError()) {
         throw new ValidationException('Invalid thread or comment');
     }
     $db = DB::conn();
     try {
         $db->begin();
         $params = array('user_id' => $this->user_id, 'title' => $this->title);
         $db->insert('thread', $params);
         $this->id = $db->lastInsertId();
         $comment->write($this->id);
         $db->commit();
     } catch (ValidationException $e) {
         $db->rollback();
         throw $e;
     }
 }
开发者ID:jeszytanada,项目名称:BoardJeszy,代码行数:27,代码来源:thread.php

示例12: Comment

require_once '../database_access.php';
$comment = new Comment();
if (isset($_POST['creation_date'])) {
    $comment->setCreationDate($_POST['creation_date']);
}
if (isset($_POST['edit_date'])) {
    $comment->setEditDate($_POST['edit_date']);
}
if (isset($_POST['author_user_id'])) {
    $comment->setAuthorUserId($_POST['author_user_id']);
}
if (isset($_POST['target_event_id'])) {
    $comment->setTargetEventId($_POST['target_event_id']);
}
if (isset($_POST['comment_text'])) {
    $comment->setCommentText($_POST['comment_text']);
}
if (!$comment->validate()) {
    foreach ($comment->getValidationFailures() as $failure) {
        echo '<p><strong>Error in ' . $failure->getPropertyPath() . ' field!</strong> ' . $failure->getMessage() . '</p>';
    }
    unset($failure);
} else {
    $comment->save();
    // add the author name and return the JSON
    $comment_json = json_decode($comment->toJSON());
    $author = $comment->getAuthor();
    $comment_json->authorFirstName = $author->getFirstName();
    $comment_json->authorLastName = $author->getLastName();
    echo json_encode($comment_json);
}
开发者ID:Web-Systems-Development-Team,项目名称:RPIwannahangout,代码行数:31,代码来源:create_comment_ajax.php

示例13: error_reporting

<?php

// Error reporting:
error_reporting(E_ALL ^ E_NOTICE);
include "application/connect.php";
include "application/comment/comment.class.php";
/*
/	This array is going to be populated with either
/	the data that was sent to the script, or the
/	error messages.
/*/
$arr = array();
$validates = Comment::validate($arr);
if ($validates) {
    /* Everything is OK, insert to database: */
    mysql_query("\tINSERT INTO comments(commentID,uID,commentText)\n\t\t\t\t\tVALUES (\n\t\t\t\t\t\t'" . $arr['commentID'] . "',\n\t\t\t\t\t\t'" . $arr['uID'] . "'\n\t\t\t\t\t\t'" . $arr['commentText'] . "'\n\t\t\t\t\t)");
    $arr['date'] = date('r', time());
    $arr['commentID'] = mysql_insert_id();
    /*
    	/	The data in $arr is escaped for the mysql query,
    	/	but we need the unescaped variables, so we apply,
    	/	stripslashes to all the elements in the array:
    	/*/
    $arr = array_map('stripslashes', $arr);
    $insertedComment = new Comment($arr);
    /* Outputting the markup of the just-inserted comment: */
    echo json_encode(array('status' => 1, 'html' => $insertedComment->markup()));
} else {
    /* Outputtng the error messages */
    echo '{"status":0,"errors":' . json_encode($arr) . '}';
}
开发者ID:nowakp,项目名称:CIT313Fall2014,代码行数:31,代码来源:submit.php

示例14: actionComment

 public function actionComment()
 {
     $comment = new Comment();
     if (isset($_POST['Comment'])) {
         $comment->shareId = $_POST['Comment']['shareId'];
         $comment->createTime = time();
         $comment->replyId = $_POST['Comment']['replyId'];
         $comment->content = $_POST['Comment']['content'];
         $comment->userId = Yii::app()->user->userId;
         $clientFlash = new ClientFlash();
         if ($comment->validate() && $comment->save()) {
             $clientFlash->setFlash(0, 'comment', '评论成功');
         } else {
             $clientFlash->setFlash(1, 'comment', '评论失败');
         }
     }
     $this->render('comment', array('commentForm' => $comment));
 }
开发者ID:tiger2soft,项目名称:travelman,代码行数:18,代码来源:ManYouDaiController.php

示例15: newComment

 function newComment()
 {
     foreach ($_POST as $k => $v) {
         $_POST[$k] = trim($v);
     }
     if ($_POST['url'] == 'http://' || empty($_POST['url'])) {
         unset($_POST['url']);
     }
     //strip html tags in comment
     if (!empty($_POST['content'])) {
         $_POST['content'] = strip_tags($_POST['content']);
     }
     Doo::loadModel('Comment');
     $c = new Comment($_POST);
     $this->prepareSidebar();
     // 'skip' is same as DooValidator::CHECK_SKIP
     if ($error = $c->validate('skip')) {
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->data['title'] = 'Oops! Error Occured!';
         $this->data['content'] = '<p style="color:#ff0000;">' . $error . '</p>';
         $this->data['content'] .= '<p>Go <a href="javascript:history.back();">back</a> to post.</p>';
         $this->render('error', $this->data);
     } else {
         Doo::autoload('DooDbExpression');
         $c->createtime = new DooDbExpression('NOW()');
         $c->insert();
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->render('comment', $this->data);
     }
 }
开发者ID:mindaugas-valinskis,项目名称:doophp,代码行数:30,代码来源:BlogController.php


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