时时商务社区
标题:
Yii实现单用户博客系统文章详情页插入评论表单的方法
[打印本页]
作者:
bewin83
时间:
2018-2-14 05:40
本文实例讲述了Yii实现单用户博客系统文章详情页插入评论表单的方法。分享给大家供大家参考,具体如下:
action部分:
var=10;
}
class one
{
public $var=1;
}
$obj=new one();
echo $obj->var.'';
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页面:
...
Leave a Comment
user->hasFlash('commentSubmitted')): ?>
user->getFlash('commentSubmitted'); ?>
renderPartial('/comment/_form',array(
'model'=>$comment,
)); ?>
...
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。
您可能感兴趣的文章:
解析yii数据库的增删查改
Yii操作数据库的3种方法
Yii实现MySQL多数据库和读写分离实例分析
Yii2.0高级框架数据库增删改查的一些操作
Yii中CGridView实现批量删除的方法
浅析Yii2 gridview实现批量删除教程
Yii2如何批量添加数据
JavaScript中全选、全不选、反选、无刷新删除、批量删除、即点即改入库(在yii框架中操作)的代码分享
yii2使用GridView实现数据全选及批量删除按钮示例
Yii实现复选框批量操作实例代码
Yii2 批量插入、更新数据实例
YII框架批量插入数据的方法
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2