首页 > 编程 > PHP > 正文

如何使用Yii实现单用户博客系统文章详情页插入评论表单的方法

2020-03-22 17:01:53
字体:
来源:转载
供稿:网友
首页 > html' target='_blank'>php教程 > php教程 > 正文 如何使用Yii实现单用户博客系统文章详情页插入评论表单的方法 2018-06-19 14:51:28 第六期线上培训班
这篇文章主要介绍了Yii实现单用户博客系统文章详情页插入评论表单的方法,结合实例分析了Yii实现文章详情页评论表单功能的具体技巧,需要的朋友可以参考下

本文实例讲述了Yii实现单用户博客系统文章详情页插入评论表单的方法。分享给大家供大家参考,具体如下:

action部分:

 ?phpfunction test($objs) $objs- var=10;class one public $var=1;$obj=new one();echo $obj- var. p test($obj);echo $obj- exit;

PostController.php页面

...* Displays a particular model.* @param integer $id the ID of the model to be displayedpublic 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-  return $comment- save();...

post/view.php页面:

... p id= comments  h3 Leave a Comment /h3  ?php if(Yii::app()- user- hasFlash( commentSubmitted )): ?  p >

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP !

相关推荐:

对于PHP中的Yii框架自带前端资源包的使用分析

关于Yii中处理前后台登录的方法实现

以上就是如何使用Yii实现单用户博客系统文章详情页插入评论表单的方法的详细内容,PHP教程

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表