建立控制器
<?php namespace app\widgets; use yii\base\Widget; use yii\helpers\Html; class TestWidget extends Widget { public $inter_info,$mapping_info; public function init() { parent::init(); $this->setView($this->render('test',['inter_info'=>$this->inter_info,'mapping_info'=>$this->mapping_info])); } public function run() { return $this->getView(); } }
建立模版
<table class="table"> <thead> <tr> <th>接口名称</th> <th>状态</th> <th>操作</th> </tr> </thead> <tbody> <?php foreach($inter_info as $k =>$v){?> <tr> <td><?php echo $v['name']; ?></td> <td><?php if(isset($mapping_info[$v['id']])){ echo '启用'; }else{ echo '禁用'; }?></td> <td><a href="/?r=app/edit_role&id=<?php echo $v['id']?>">编辑</a></td> </tr> <?php }?> </tbody> </table>
调用
<?= TestWidget::widget(['inter_info' =>$inter_info,'mapping_info'=>$mapping_info]) ?>