发布于 2015-12-31 02:24:59 | 176 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的YII 2.0教程,程序狗速度看过来!

Yii高性能PHP框架

Yii Framework是一个基于组件、用于开发大型 Web 应用的高性能 PHP 框架。Yii提供了今日Web 2.0应用开发所需要的几乎一切功能。Yii是最有效率的PHP框架之一。Yii是创始人薛强的心血结晶,于2008年1月1日开始开发。


这篇文章主要介绍了Yii实现单用户博客系统文章详情页插入评论表单的方法,结合实例分析了Yii实现文章详情页评论表单功能的具体技巧,需要的朋友可以参考下

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

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

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务