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.