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 commentuser->hasflash('commentsubmitted')): ?> user->getflash('commentsubmitted'); ?>
renderpartial('/comment/_form',array( 'model'=>$comment, )); ?>
...
希望本文所述对大家基于yii框架的php程序设计有所帮助。
以上就介绍了yii实现单用户博客系统文章详情页插入评论表单的方法,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
