yh / yii2-switchery
为yii2的switchery
dev-master
2018-01-31 08:44 UTC
Requires
- bower-asset/switchery: >=0.8.0
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2024-09-22 04:26:58 UTC
README
为yii2的switchery
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist yh/yii2-switchery "dev-master"
或者在您的 composer.json
文件的 require 部分添加:
"yh/yii2-switchery": "dev-master"
使用方法
扩展安装完成后,您只需在代码中通过
视图
<?= GridView::widget([ 'dataProvider' => $dataProvider, 'tableOptions' => ['class' => 'table table-striped'], 'columns' => [ 'id', 'username', 'email:email', 'status', [ 'class' => 'yh\switchery\Switchery', 'attribute' => 'status', 'action' => 'user/status',//发送ajax的地址 'callBack' => 'function(data){console.log(data)}', 'statusOpen' =>10,//default 10 'statusClose' =>0//default 0 ], 'created_at:datetime', 'updated_at:datetime', ], ]); ?>
控制器
public function actionStatus($key,$status) { \Yii::$app->getResponse()->format = 'json'; $model = User::findOne($key); $model->status = $status; $model->save(false); return ['code' => 0,'message' => 'ok']; }