Yii: how to insert a comment form to the details page of a single-user blog system. yii form _ PHP Tutorial

Source: Internet
Author: User
Yii implements the method of inserting a comment form into the document details page of a single-user blog system, yii form. Yii implements the method of inserting a comment form on the details page of a single-user blog system article. this example describes how yii inserts a comment form into the details page of a single-user blog system article. Yii is used to insert a comment form into the document details page of a single user blog system. yii form

This example describes how to insert a comment form into the details page of a single-user blog system. We will share this with you for your reference. The details are as follows:

Action:

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

...

I hope this article will help you design PHP programs based on the Yii Framework.

Articles you may be interested in:
  • YiiFramework knowledge point summary (graphic tutorial)
  • Directory structure, entry file, and route settings in Yii Getting Started Tutorial
  • Yii installation and hello world
  • Yii PHP Framework practical Getting Started Tutorial (details)
  • Yii Query Builder usage example tutorial
  • How to beautify YII by using url components
  • Batch delete of CGridView in Yii
  • Yii Quick Start Classic Tutorial

Examples in this article describes how Yii inserts a comment form into the details page of a single-user blog system article. Points...

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.