Yii实现单用户博客系统文章详情页插入评论表单的方法
更新时间:2015年12月28日 14:10:24 作者:zm2714
这篇文章主要介绍了Yii实现单用户博客系统文章详情页插入评论表单的方法,结合实例分析了Yii实现文章详情页评论表单功能的具体技巧,需要的朋友可以参考下
本文实例讲述了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程序设计有所帮助。
相关文章
php使用workman框架实现socket服务以及连接客户端
这篇文章主要介绍了php使用workman框架实现socket服务以及连接客户端,本文列举了详细的过程和代码展示,能够帮助你学习,需要的朋友可以参考下2021-06-06
PHP实现微信支付(jsapi支付)和退款(无需集成支付SDK)流程教程详解
本篇文章给大家介绍PHP实现微信支付(jsapi支付)和退款(无需集成支付SDK)流程教程详解,使用了微信官方给的php版本的sdk,但是在使用过程中有很多问题,今天给大家讲讲不集成支付SDK直接调用支付接口实现支付和退款,感兴趣的朋友一起看看吧2018-03-03
Codeigniter出现错误提示Error with CACHE directory的解决方案
这篇文章主要介绍了Codeigniter出现错误提示Error with CACHE directory的解决方案,需要的朋友可以参考下2014-06-06


最新评论