Yii realize single User blog system article detail page Insert comment Form _php instance

Source: Internet
Author: User
Tags yii

This article is an example of how Yii realizes the single user blog system article details page inserts the comment form the method. Share to everyone for your reference, specific as follows:

Action section:

<?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

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:

...
<div id= "Comments" >
 
 

I hope this article will help you with the PHP program design based on the 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.