How to use Yii to implement a single-user blog system article details page insert a Comment form method

Source: Internet
Author: User
Tags yii
This article mainly describes the Yii implementation of the single-user blog system article details page Insert Comment form method, combined with an example of YII implementation of the article Details page comment form function of the specific skills, the need for friends can refer to the next

In this paper, we describe the method that Yii implements the Single User blog system article detail page to insert a comment form. Share to everyone for your reference, as follows:

Action section:

<?phpfunction Test ($OBJS) {$objs->var=10;} Class one{Public $var = 1;} $obj =new One (), echo $obj->var ' <p> '; test ($obj); Echo $obj->var;exit;

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;} ...

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 ();} ...

post/view.php page:

... <p id= "comments" >

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.