yh/yii2-switchery

switchery for yii2

Installs: 127

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

dev-master 2018-01-31 08:44 UTC

This package is not auto-updated.

Last update: 2024-05-05 02:52:07 UTC


README

switchery for yii2 images 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'];
}