您的位置:首页 > 编程语言 > PHP开发

Yii2 自定义组件

2015-08-27 22:51 666 查看
basic\components\HelloWidget


namespace app\components;
use yii\base\Widget;
use yii\helpers\Html;

class HelloWidget extends Widget
{
public $message;

public function init()
{
parent::init();
if ($this->message === null) {
$this->message = '您好';
}
}

public function run()
{
return Html::encode($this->message);
}


  

View

[php] view plaincopy在CODE上查看代码片派生到我的代码片
<?php
use app\components\HelloWidget;
?>
<?= HelloWidget::widget(['message' => '组件']) ?>


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: