Yii實現(xiàn)單用戶博客系統(tǒng)文章詳情頁插入評論表單的方法
更新時間:2015年12月28日 14:10:24 作者:zm2714
這篇文章主要介紹了Yii實現(xiàn)單用戶博客系統(tǒng)文章詳情頁插入評論表單的方法,結(jié)合實例分析了Yii實現(xiàn)文章詳情頁評論表單功能的具體技巧,需要的朋友可以參考下
本文實例講述了Yii實現(xiàn)單用戶博客系統(tǒ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 -->
...
希望本文所述對大家基于Yii框架的PHP程序設(shè)計有所幫助。
您可能感興趣的文章:
- Yii2 批量插入、更新數(shù)據(jù)實例
- Yii實現(xiàn)復(fù)選框批量操作實例代碼
- yii2使用GridView實現(xiàn)數(shù)據(jù)全選及批量刪除按鈕示例
- JavaScript中全選、全不選、反選、無刷新刪除、批量刪除、即點即改入庫(在yii框架中操作)的代碼分享
- Yii2如何批量添加數(shù)據(jù)
- 淺析Yii2 gridview實現(xiàn)批量刪除教程
- Yii中CGridView實現(xiàn)批量刪除的方法
- Yii操作數(shù)據(jù)庫的3種方法
- 解析yii數(shù)據(jù)庫的增刪查改
- Yii實現(xiàn)MySQL多數(shù)據(jù)庫和讀寫分離實例分析
- Yii2.0高級框架數(shù)據(jù)庫增刪改查的一些操作
- YII框架批量插入數(shù)據(jù)的方法
相關(guān)文章
php+mysql+ajax 局部刷新點贊/取消點贊功能(每個賬號只點贊一次)
這篇文章主要介紹了php+mysql+ajax 局部刷新點贊/取消點贊功能(每個賬號只點贊一次),本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07
關(guān)于laravel模板中生成URL的幾種模式總結(jié)
今天小編就為大家分享一篇關(guān)于laravel模板中生成URL的幾種模式總結(jié),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10
有道搜索和IP138的IP的API接口(PHP應(yīng)用)
原理就是通過php模擬瀏覽器獲取ip地址歸屬地,需要的朋友可以參考下2012-11-11
PHP刪除字符串中非字母數(shù)字字符方法總結(jié)
在本篇文章里小編給大家分享了關(guān)于PHP刪除字符串中非字母數(shù)字字符方法和知識點,有需要的朋友們學(xué)習(xí)下。2019-01-01

