本文整理汇总了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'));
}
示例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);
}
示例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;
}
示例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)));
}
示例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;
}
示例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);
}
示例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!');
}
}
示例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();
}
示例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();
}
}
示例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();
}
}
}
示例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;
}
}
示例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);
}
示例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) . '}';
}
示例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));
}
示例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);
}
}