PHP code example of porcelanosa / yii2-toggle-column

1. Go to this page and download the library: Download porcelanosa/yii2-toggle-column library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

porcelanosa / yii2-toggle-column example snippets


composer 


use porcelanosa\yii2togglecolumn\ToggleAction;
use app\models\Artists;
class ArtistsController	extends Controller
{
//.............
public function actions()	{
			return [
				'toggle' => [
					'class' => ToggleAction::className(),
					'modelClass' => Artists::className(),
					// Uncomment to enable flash messages
					//'setFlash' => true,
					'attribute' => 'active',
					'primaryKey' => 'id'
				],
			]
	}
//.......
}
	

 <?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        *['class' => 'yii\grid\SerialColumn'],

        'id',
        [
            'class' => 'app\modules\admin\components\columns\ToggleColumn',
            'attribute' => 'active',
            // Uncomment if  you don't want AJAX
            'enableAjax' => true,
            'contentOptions' => ['style' => 'width:50px;']
        ],
        ['class' => ActionColumn::className()],
    ],
    ]);