欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Yii實(shí)現(xiàn)單用戶博客系統(tǒng)文章詳情頁插入評(píng)論表單的方法

 更新時(shí)間:2015年12月28日 14:10:24   作者:zm2714  
這篇文章主要介紹了Yii實(shí)現(xiàn)單用戶博客系統(tǒng)文章詳情頁插入評(píng)論表單的方法,結(jié)合實(shí)例分析了Yii實(shí)現(xiàn)文章詳情頁評(píng)論表單功能的具體技巧,需要的朋友可以參考下

本文實(shí)例講述了Yii實(shí)現(xiàn)單用戶博客系統(tǒng)文章詳情頁插入評(píng)論表單的方法。分享給大家供大家參考,具體如下:

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 -->
...

希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論