Yii實現單使用者部落格系統文章詳情頁插入評論表單的方法_php執行個體

來源:互聯網
上載者:User
本文執行個體講述了Yii實現單使用者部落格系統文章詳情頁插入評論表單的方法。分享給大家供大家參考,具體如下:

action部分:

<?phpfunction test($objs){ $objs->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

<?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?> <?php echo Yii::app()->user->getFlash('commentSubmitted'); ?> <?php else: ?> <?php $this->renderPartial('/comment/_form',array( 'model'=>$comment, )); ?><?php endif; ?>...

希望本文所述對大家基於Yii架構的PHP程式設計有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.