yii2 中的 ActionColumn

默认情况下有ActionColumn, view, update。delete


我想添加一个“已完成”按钮来将任务标记为已完成,(我在 db 调用状态中有一列获得 int 0 或 1),所以我想要一个实现逻辑以将任务标记为已完成的函数,某人可以帮我吗?


这个例子我在论坛上弄的,但是不是很懂


[

  'class' => 'yii\grid\ActionColumn',

  'template' => '{view} {update} {delete} {made}',

  'buttons'=> [

    'made' => function () {     

      return Html::button('<span class="glyphicon glyphicon-ok"></span>', [

        'title' => Yii::t('yii', 'made'),

      ]);                                

    }

  ],


慕丝7291255
浏览 122回答 1
1回答

偶然的你

你可以这样做:[&nbsp; 'class' => 'yii\grid\ActionColumn',&nbsp; 'template' => '{view} {update} {delete} {made}',&nbsp; 'buttons'=> [&nbsp; &nbsp; ...&nbsp; &nbsp; 'made' => function ($url, $model) {&nbsp; &nbsp; &nbsp; &nbsp;if($model->status === $model::STATUS_SUSPENDED){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Html::a("Activate", $url, [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'title' => "Activate",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'class' => 'btn btn-xs btn-success',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'data' => [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'method' => 'post',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'confirm' => 'Are you sure? This will Activate this.',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]);&nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp;return Html::a("Suspend", $url, [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'title' => "Suspend",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'class' => 'btn btn-xs btn-danger',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'data' => [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'method' => 'post',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'confirm' => 'Are you sure? This will Suspend this.',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],&nbsp; &nbsp; &nbsp; &nbsp;]);&nbsp; &nbsp; &nbsp;}&nbsp; ],]actionMade()然后在检查请求的控制器中创建方法post,并对指定的id. 希望这会有所帮助。
打开App,查看更多内容
随时随地看视频慕课网APP