<?= Html::a('删除', ['post/delete', 'id' => $post['id']],['data-confirm'=>'确定要删除吗?']) ?>
<?= Html::a('Do Something', ['my-action', 'id' => $id], [ 'class' => 'btn btn-primary', 'data' => [ 'confirm' => 'Are you sure you want to do?', 'method' => 'post', ], ]) ?>
原因是yii.js未自动引入, 去asset里面设置一下
以下是我的appasset.php文件配置
class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ 'css/site.css', 'static/css/tabs.css', ]; public $js = [ '/static/js/jquery-migrate.js', '/static/js/AdminLTE.min.js', ]; public $depends = [ 'yii\web\YiiAsset', 'yii\web\JqueryAsset', 'yii\bootstrap\BootstrapAsset', 'backend\assets\AdminLTEAsset' ]; }