国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

Yii實現單用戶博客系統文章詳情頁插入評論表單的方法

2024-05-04 23:41:36
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了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->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教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 治多县| 南靖县| 泽普县| 双峰县| 会昌县| 四川省| 绥阳县| 绍兴市| 吉安市| 鹿邑县| 安庆市| 海安县| 华容县| 喀什市| 潮州市| 安义县| 大冶市| 东乡县| 新蔡县| 贵南县| 六盘水市| 日照市| 怀来县| 隆林| 许昌县| 堆龙德庆县| 龙山县| 鱼台县| 绥中县| 绥宁县| 车险| 塔城市| 吴桥县| 绥芬河市| 河间市| 新邵县| 洛隆县| 彰武县| 周宁县| 北海市| 板桥市|