柴门鸟雀噪,归客千里至。光明顶下来,一路听着阵阵松涛,我们走过西海,飞来石,天海,爬过百步云梯,伴着凤凰松迎客松的多姿到了玉屏峰。玉屏峰犹如一道屏障,山面光滑如镜子,如屏风,还不时有几个斗大的字,说是哪位名人留下的。玉屏峰最险的地方是在一线天,上下达七八十度的落差,台阶狭,仅容一人,台阶窄,仅托一足,百米长,走多了,腿便打抖了,害怕了,还不时地叫着好刺激呀。
本文实例讲述了Yii实现单用户博客系统文章详情页插入评论表单的方法。分享给大家供大家参考,具体如下:
action部分:
<?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 id="comments"> <h3>Leave a Comment</h3> <?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?> <div class="flash-success"> <?php echo Yii::app()->user->getFlash('commentSubmitted'); ?> </div> <?php else: ?> <?php $this->renderPartial('/comment/_form',array( 'model'=>$comment, )); ?> <?php endif; ?> </div><!-- comments --> ...
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。
以上就是Yii实现单用户博客系统文章详情页插入评论表单的方法。小苗不经风雨长不成大树,人不经困难难以成材。更多关于Yii实现单用户博客系统文章详情页插入评论表单的方法请关注haodaima.com其它相关文章!