Yii implementation of single-user blog system article details page Insert Comment form method _php instance

Source: Internet
Author: User
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. '

'; 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:

...

Leave a Comment

<?php if (Yii::app ()->user->hasflash (' commentsubmitted '):?> <?php Echo yii::app ()->user- >getflash (' commentsubmitted ');?> <?php Else:?> <?php $this->renderpartial ('/comment/_form ', array (' model ' = $comment,)); ><?php endif;?> ...

It is hoped that this article is helpful to the PHP program design based on YII framework.

  • 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.