码迷,mamicode.com
首页 > 其他好文 > 详细

yii2 widget示例

时间:2016-06-08 10:41:22      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

<?php
namespace app\components;

use yii\base\Widget;
use yii\helpers\Html;

class RctReplyWidget extends Widget{
    public $commentDataProvider;

    public function init(){
        parent::init();
    }

    public function run(){
        $commentString=‘‘;
         foreach($this->commentDataProvider as $comment){
             $commentString.=‘<div class="post">‘.
                            ‘<div class="title">‘.
                            ‘<p style="color:#777777;font-style:italic;">‘.nl2br($comment->content).‘</p>‘.
                            ‘<p class="text-right"><span class="glyphicon glyphicon-user" aria-hidden="true"></span>‘.Html::encode($comment->author).‘</p>‘.
                            ‘<p style="font-size:8pt;color:blue">《 <a href="‘.$comment->post->url.‘">‘.Html::encode($comment->post->title).‘</a>》</p>‘.
                            ‘<hr></div></div>‘;
         }
    return $commentString;
    }
}
<?= RctReplyWidget::widget([‘commentDataProvider‘ => $commentDataProvider]); ?>

 

yii2 widget示例

标签:

原文地址:http://www.cnblogs.com/LoveJulin/p/5569180.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!