PHP code example of liyunfang / yii2-contextmenu
1. Go to this page and download the library: Download liyunfang/yii2-contextmenu 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/ */
liyunfang / yii2-contextmenu example snippets
'columns' => [
[
'class' => \liyunfang\contextmenu\SerialColumn::className(),
'contextMenu' => true,
//'contextMenuAttribute' => 'id',
'template' => '{view} {update} <li class="divider"></li> {story}',
'buttons' => [
'story' => function ($url, $model) {
$title = Yii::t('app', 'Story');
$label = '<span class="glyphicon glyphicon-film"></span> ' . $title;
$url = \Yii::$app->getUrlManager()->createUrl(['/user/story','id' => $model->id]);
$options = ['tabindex' => '-1','title' => $title, 'data' => ['pjax' => '0' , 'toggle' => 'tooltip']];
return '<li>' . Html::a($label, $url, $options) . '</li>' . PHP_EOL;
}
],
],
....
],
'rowOptions' => function($model, $key, $index, $gird){
$contextMenuId = $gird->columns[0]->contextMenuId;
return ['data'=>[ 'toggle' => 'context','target'=> "#".$contextMenuId ]];
},
'columns' => [
[
'class' => \liyunfang\contextmenu\KartikSerialColumn::className(),
'contextMenu' => true,
//'contextMenuAttribute' => 'id',
//'template' => '{view} {update}',
'contentOptions'=>['class'=>'kartik-sheet-style'],
'headerOptions'=>['class'=>'kartik-sheet-style'],
'urlCreator' => function($action, $model, $key, $index) {
if('update' == $action){
return \Yii::$app->getUrlManager()->createUrl(['/user/index','id' => $model->id]);
}
if('view' == $action){
return \Yii::$app->getUrlManager()->createUrl(['/user/view','id' => $model->id]);
}
return '#';
},
],
....
],
'rowOptions' => function($model, $key, $index, $gird){
$contextMenuId = $gird->columns[0]->contextMenuId;
return ['data'=>[ 'toggle' => 'context','target'=> "#".$contextMenuId ]];
},