Yii實(shí)現(xiàn)單用戶博客系統(tǒng)文章詳情頁(yè)插入評(píng)論表單的方法
本文實(shí)例講述了Yii實(shí)現(xiàn)單用戶博客系統(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ù)和讀寫分離實(shí)例分析
- Yii2.0高級(jí)框架數(shù)據(jù)庫(kù)增刪改查的一些操作
- YII框架批量插入數(shù)據(jù)的方法
相關(guān)文章
php使用workman框架實(shí)現(xiàn)socket服務(wù)以及連接客戶端
這篇文章主要介紹了php使用workman框架實(shí)現(xiàn)socket服務(wù)以及連接客戶端,本文列舉了詳細(xì)的過(guò)程和代碼展示,能夠幫助你學(xué)習(xí),需要的朋友可以參考下2021-06-06
ThinkPHP中create()方法自動(dòng)驗(yàn)證表單信息
這篇文章主要為大家詳細(xì)介紹了ThinkPHP中create()方法自動(dòng)驗(yàn)證表單信息,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
PHP實(shí)現(xiàn)微信支付(jsapi支付)和退款(無(wú)需集成支付SDK)流程教程詳解
本篇文章給大家介紹PHP實(shí)現(xiàn)微信支付(jsapi支付)和退款(無(wú)需集成支付SDK)流程教程詳解,使用了微信官方給的php版本的sdk,但是在使用過(guò)程中有很多問(wèn)題,今天給大家講講不集成支付SDK直接調(diào)用支付接口實(shí)現(xiàn)支付和退款,感興趣的朋友一起看看吧2018-03-03
Laravel實(shí)現(xiàn)定時(shí)任務(wù)的示例代碼
本篇文章主要介紹了Laravel實(shí)現(xiàn)定時(shí)任務(wù)的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08
Symfony2實(shí)現(xiàn)在doctrine中內(nèi)置數(shù)據(jù)的方法
這篇文章主要介紹了Symfony2實(shí)現(xiàn)在doctrine中內(nèi)置數(shù)據(jù)的方法,結(jié)合實(shí)例形式分析了在doctrine中內(nèi)置數(shù)據(jù)的具體步驟與相關(guān)技巧,需要的朋友可以參考下2016-02-02
Codeigniter出現(xiàn)錯(cuò)誤提示Error with CACHE directory的解決方案
這篇文章主要介紹了Codeigniter出現(xiàn)錯(cuò)誤提示Error with CACHE directory的解決方案,需要的朋友可以參考下2014-06-06

