yh / yii2-switchery
switchery for yii2
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: 2026-03-08 11:01:51 UTC
README
switchery for yii2
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yh/yii2-switchery "dev-master"
or add
"yh/yii2-switchery": "dev-master"
to the require section of your composer.json file.
Usage
Once the extension is installed, simply use it in your code by :
view:
<?= 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', ], ]); ?>
controller:
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']; }