demos/blog/protected/controllers/PostController.php
protected function newComment($post)
	{
		$comment=new Comment;
		if(isset($_POST['ajax']) && $_POST['ajax']==='comment-form')
		{
			echo CActiveForm::validate($comment);
			Yii::app()->end();
		}
		if(isset($_POST['Comment']))
		{
			$comment->attributes=$_POST['Comment'];
			if($post->addComment($comment))
			{
				if($comment->status==Comment::STATUS_PENDING)
					Yii::app()->user->setFlash('commentSubmitted','Thank you for your comment. Your comment will be posted once it is approved.');
				$this->refresh();
			}
		}
		return $comment;
	}
protected function newComment($post)
	{
		$comment=new Comment;
		if(isset($_POST['ajax']) && $_POST['ajax']==='comment-form')
		{
			echo CActiveForm::validate($comment);
			Yii::app()->end();
		}
		if(isset($_POST['Comment']))
		{
			$comment->attributes=$_POST['Comment'];
			if($post->addComment($comment))
			{
				if($comment->status==Comment::STATUS_PENDING)
					Yii::app()->user->setFlash('commentSubmitted','Thank you for your comment. Your comment will be posted once it is approved.');
				$this->refresh();
			}
		}
		return $comment;
	}
protected function newComment ( $ post ) { $ comment = new Comment ; if ( isset ( $ _POST [ 'ajax' ] ) && $ _POST [ 'ajax' ] === 'comment-form' ) { echo CActiveForm :: validate ( $ comment ) ; Yii :: app ( ) -> end ( ) ; } if ( isset ( $ _POST [ 'Comment' ] ) ) { $ comment -> attributes = $ _POST [ 'Comment' ] ; if ( $ post -> addComment ( $ comment ) ) { if ( $ comment -> status == Comment :: STATUS_PENDING ) Yii :: app ( ) -> user -> setFlash ( 'commentSubmitted' , 'Thank you for your comment. Your comment will be posted once it is approved.' ) ; $ this -> refresh ( ) ; } } return $ comment ; }
Creates a new comment.
This method attempts to create a new comment based on the user input.
If the comment is successfully created, the browser will be redirected
to show the created comment.
@param Post the post that the new comment belongs to
@return Comment the comment instance
Creates a new comment . This method attempts to create a new comment based on the user input . If the comment is successfully created the browser will be redirected to show the created comment .