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.