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

Yii框架的挂件的使用

2017-05-31 18:16 162 查看
参考文档

应用的场景: 页面的某一部分多次被使用

最简单的一种应用  ,但是这种写法是被弃了 ,大佬选择了写一个php文件,require 加载的模式

挂件的写法

useyii\base\Widget;

class ReportTagController extends Widget
{
public $tags;//循环的数据源
public $phas;//金融标签是不是要带上 p标签呢  0 不带  1带
public $host;

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

public function run()
{
parent::run();
if ($this->phas) {
$html = $this->getHtmlWithNoImg();
} else {
$html = $this->getHtmlWithImg();
}

return $html;

}
}


页面的写法 

<?= ReportTagController::widget(['tags'=>$tel_info,'phas'=>0,'host'=>$host]);?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: