yii2-Html助手
http://www.yiichina.com/doc/guide/2.0/helper-html
http://www.yiiframework.com/doc-2.0/guide-helper-html.html
http://www.yiiframework.com/doc-2.0/yii-helpers-html.html
Class yii\helpers\Html
PHP Code复制内容到剪贴板
- <?= Html::a(
- '删除',
- [
- 'delete',
- 'id' => $id,
- ],
- [
- 'data' => [
- 'confirm' => '你确定要删除吗?',
- 'method' => 'post',
- ],
- ]
- )
- ?>
- // html代码
PHP Code复制内容到剪贴板
- [
- 'attribute' => 'unzip',
- 'label' => 'H5压缩包',
- 'format' => 'raw', //如果format为html target属性会被过滤,所以设置为raw
- 'value' => function($model){
- if($model->data->unzip && $model->data->unzip->entrance){
- return Html::a('预览', $model->data->unzip->entrance,['class' => 'profile-link','target' => '_blank']);
- }else{
- return "暂无";
- }
- },
- ],
activeDropDownList()
PHP Code复制内容到剪贴板
- public static string activeDropDownList ( $model, $attribute, $items, $options = [] )
PHP Code复制内容到剪贴板
- <?= Html::a('<span class="glyphicon glyphicon-eye-open"></span>', ['view', 'id' => $model->id], [
- 'class' => 'btn btn-default btn-xs',
- ]);
- ?>
- <?= Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['update', 'id' => $model->id], [
- 'class' => 'btn btn-default btn-xs'
- ]);
- ?>
- <?= Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $model->id], [
- 'class' => 'btn btn-default btn-xs',
- 'data-confirm' => '删除后不能恢复,确定要删除吗?',
- 'data-method' => 'post',
- ]);
- ?>
这里是JS对data-后面的数据进行了处理,也可以最上面那种写法
本文来自于:http://www.yiiframework.com/doc-2.0/yii-helpers-html.html
下一篇 yii2 数据库操作