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

