Table of Contents
Yii implements the method of inserting a comment form into the article details page of a single-user blog system, yii form
Articles you may be interested in:
Home Backend Development PHP Tutorial Yii implements the method of inserting a comment form into the article details page of a single-user blog system, yii form_PHP tutorial

Yii implements the method of inserting a comment form into the article details page of a single-user blog system, yii form_PHP tutorial

Jul 12, 2016 am 09:02 AM
yii form Comment

Yii implements the method of inserting a comment form into the article details page of a single-user blog system, yii form

This article describes an example of how Yii implements the method of inserting a comment form into the article details page of a single-user blog system . Share it with everyone for your reference, the details are as follows:

action part:

<?php
function test($objs)
{
 $objs->var=10;
}
class one
{
 public $var=1;
}
$obj=new one();
echo $obj->var.'<p>';
test($obj);
echo $obj->var;
exit;

Copy after login

PostController.php page:

...
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
  $post=$this->loadModel($id);
  $comment=$this->newComment($post);
  $this->render('view',array(
    'model'=>$post,
    'comment'=>$comment,
  ));
}
protected function newComment($post)
{
  $comment=new Comment();
  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...');
    $this->refresh();
   }
  }
  return $comment;
}
...

Copy after login

models/Post.php page:

...
public function addComment($comment)
{
  if(Yii::app()->params['commentNeedApproval'])
   $comment->status=Comment::STATUS_PENDING;
  else
   $comment->status=Comment::STATUS_APPROVED;
  $comment->post_id=$this->id;
  return $comment->save();
}
...

Copy after login

post/view.php page:

...
<div id="comments">
<h3>Leave a Comment</h3>
<?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?>
 <div class="flash-success">
 <?php echo Yii::app()->user->getFlash('commentSubmitted'); ?>
 </div>
<?php else: ?>
 <?php $this->renderPartial('/comment/_form',array(
 'model'=>$comment,
 )); ?>
<?php endif; ?>
</div><!-- comments -->
...

Copy after login

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

Articles you may be interested in:

  • Summary of YiiFramework introductory knowledge points (graphic tutorial)
  • Yii introductory tutorial directory structure, entry file and routing settings
  • Yii introductory tutorial - Yii installation and hello world
  • Yii PHP Framework practical introductory tutorial (detailed introduction)
  • Yii query builder (Query Builder) usage example tutorial
  • How to use url component to beautify management in YII
  • How to implement batch deletion of CGridView in Yii
  • Yii Quick Start Classic Tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1085879.htmlTechArticleYii implements the method of inserting the comment form into the article details page of the single-user blog system, yii form. This article describes the example of Yii implementing the single-user blog system. How to insert a comment form into the user blog system article details page. Points...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Why is the latest comment on Xiaohongshu at the bottom? How does Xiaohongshu make its comments number one? Why is the latest comment on Xiaohongshu at the bottom? How does Xiaohongshu make its comments number one? Mar 21, 2024 pm 06:21 PM

Why is the latest comment on Xiaohongshu at the bottom? How does Xiaohongshu make its comments number one?

How do I delete my comments on TikTok? How can others find out my comments on TikTok? How do I delete my comments on TikTok? How can others find out my comments on TikTok? Mar 21, 2024 pm 10:41 PM

How do I delete my comments on TikTok? How can others find out my comments on TikTok?

Why is Xiaohongshu's own comment at the bottom? How to modify a comment on Xiaohongshu? Why is Xiaohongshu's own comment at the bottom? How to modify a comment on Xiaohongshu? Mar 21, 2024 pm 10:46 PM

Why is Xiaohongshu's own comment at the bottom? How to modify a comment on Xiaohongshu?

Why can't others see my comments on Xiaohongshu? Why can't others see its comments? Why can't others see my comments on Xiaohongshu? Why can't others see its comments? Mar 21, 2024 pm 07:51 PM

Why can't others see my comments on Xiaohongshu? Why can't others see its comments?

Why can't pictures be displayed in Xiaohongshu comments? Why is the Xiaohongshu IP address not updated? Why can't pictures be displayed in Xiaohongshu comments? Why is the Xiaohongshu IP address not updated? Mar 21, 2024 pm 09:00 PM

Why can't pictures be displayed in Xiaohongshu comments? Why is the Xiaohongshu IP address not updated?

Will I be reminded if my Xiaohongshu comment is deleted by the blogger? What should I do if my comments in Xiaohongshu are deleted? Will I be reminded if my Xiaohongshu comment is deleted by the blogger? What should I do if my comments in Xiaohongshu are deleted? Mar 28, 2024 am 11:46 AM

Will I be reminded if my Xiaohongshu comment is deleted by the blogger? What should I do if my comments in Xiaohongshu are deleted?

How to pin comments to the top of Xiaohongshu on the computer? Where are the private messages on the computer? How to pin comments to the top of Xiaohongshu on the computer? Where are the private messages on the computer? Mar 28, 2024 pm 12:36 PM

How to pin comments to the top of Xiaohongshu on the computer? Where are the private messages on the computer?

How to add people who comment on WeChat video accounts as friends? How do you know who the person who commented on the video account is? How to add people who comment on WeChat video accounts as friends? How do you know who the person who commented on the video account is? Apr 01, 2024 pm 05:06 PM

How to add people who comment on WeChat video accounts as friends? How do you know who the person who commented on the video account is?

See all articles