PHP Classes

File: views/test/index.php

Recommend this page to a friend!
  Classes of Uldis Nelsons   YII2 Framework PHP Init   views/test/index.php   Download  
File: views/test/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: YII2 Framework PHP Init
Create a project based on the YII2 from template
Author: By
Last change:
Date: 3 years ago
Size: 3,882 bytes
 

Contents

Class file image Download
<?php

use yii\helpers\Html;
use
yii\helpers\Url;
use
yii\grid\GridView;

/**
* @var yii\web\View $this
* @var yii\data\ActiveDataProvider $dataProvider
    * @var app\models\TestSearch $searchModel
*/



/**
* create action column template depending acces rights
*/
$actionColumnTemplates = [];

//if (\Yii::$app->user->can('app_test_view')) {
   
$actionColumnTemplates[] = '{view}';
//}

//if (\Yii::$app->user->can('app_test_update')) {
   
$actionColumnTemplates[] = '{update}';
//}

//if (\Yii::$app->user->can('app_test_delete')) {
   
$actionColumnTemplates[] = '{delete}';
//}
if (isset($actionColumnTemplates)) {
$actionColumnTemplate = implode(' ', $actionColumnTemplates);
   
$actionColumnTemplateString = $actionColumnTemplate;
} else {
Yii::$app->view->params['pageButtons'] = Html::a('<span class="glyphicon glyphicon-plus"></span> ' . Yii::t('app', 'New'), ['create'], ['class' => 'btn btn-success']);
   
$actionColumnTemplateString = "{view} {update} {delete}";
}
?>
<div class="giiant-crud test-index">

    <?php // echo $this->render('_search', ['model' =>$searchModel]);
       
?>

   
    <?php \yii\widgets\Pjax::begin(['id'=>'pjax-main', 'enableReplaceState'=> false, 'linkSelector'=>'#pjax-main ul.pagination a, th a', 'clientOptions' => ['pjax:success'=>'function(){alert("yo")}']]) ?>

    <h1>
        <?= Yii::t('app', 'Tests') ?> <small>
            List
        </small>
    </h1>
    <div class="clearfix crud-navigation">
        <div class="pull-left">
            <?= Html::a('<span class="glyphicon glyphicon-plus"></span> ' . Yii::t('app', 'New'), ['create'], ['class' => 'btn btn-success']) ?>
</div>

        <div class="pull-right">

                       
            <?=
           
\yii\bootstrap\ButtonDropdown::widget(
            [
           
'id' => 'giiant-relations',
           
'encodeLabel' => false,
           
'label' => '<span class="glyphicon glyphicon-paperclip"></span> ' . Yii::t('app', 'Relations'),
           
'dropdown' => [
           
'options' => [
           
'class' => 'dropdown-menu-right'
           
],
           
'encodeLabels' => false,
           
'items' => [ [
                      
'url' => ['test-contacts/index'],
                      
'label' => '<i class="glyphicon glyphicon-arrow-right">&nbsp;' . Yii::t('app', 'Test Contacts') . '</i>',
                   ],]
            ],
           
'options' => [
           
'class' => 'btn-default'
           
]
            ]
            );
           
?> </div>
    </div>

    <hr />

    <div class="table-responsive">
        <?= GridView::widget([
       
'layout' => '{summary}{pager}{items}{pager}',
       
'dataProvider' => $dataProvider,
       
'pager' => [
       
'class' => yii\widgets\LinkPager::className(),
       
'firstPageLabel' => Yii::t('app', 'First'),
       
'lastPageLabel' => Yii::t('app', 'Last') ],
                   
'filterModel' => $searchModel,
               
'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'],
       
'headerRowOptions' => ['class'=>'x'],
       
'columns' => [

                [
           
'class' => 'yii\grid\ActionColumn',
           
'template' => $actionColumnTemplateString,
           
'urlCreator' => function($action, $model, $key, $index) {
               
// using the column name as key, not mapping to 'id' like the standard generator
               
$params = is_array($key) ? $key : [$model->primaryKey()[0] => (string) $key];
               
$params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id . '/' . $action : $action;
                return
Url::toRoute($params);
            },
           
'contentOptions' => ['nowrap'=>'nowrap']
        ],
           
'createdate',
           
'update_dt',
           
'name',
           
'description',
        ],
        ]);
?>
</div>

</div>


<?php \yii\widgets\Pjax::end() ?>