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!