Yii实现单用户博客系统文章详情页插入评论表单

<?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页面:

... /** * 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页面:

... 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页面:

... <div> <h3>Leave a Comment</h3> <?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?> <div> <?php echo Yii::app()->user->getFlash('commentSubmitted'); ?> </div> <?php else: ?> <?php $this->renderPartial('/comment/_form',array( 'model'=>$comment, )); ?> <?php endif; ?> </div><!-- comments --> ...

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/16feac44d755e6863137032ff774ecac.html