PHP Classes

File: views/test-contacts/index.php

Recommend this page to a friend!
  Classes of Uldis Nelsons   YII2 Framework PHP Init   views/test-contacts/index.php   Download  
File: views/test-contacts/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: 2 years ago
Size: 4,462 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\TestContactsSearch $searchModel
*/



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

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

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

//if (\Yii::$app->user->can('app_test-contacts_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-contacts-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', 'TestContacts') ?> <small>
            List
        </small>
    </h1>
    <div class="clearfix crud-navigation">
<?php
//if(\Yii::$app->user->can('app_test-contacts_create')){
?>
<div class="pull-left">
            <?= Html::a('<span class="glyphicon glyphicon-plus"></span> ' . Yii::t('app', 'New'), ['create'], ['class' => 'btn btn-success']) ?>
</div>
<?php
//}
?>
<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/index'],
               
'label' => '<i class="glyphicon glyphicon-arrow-right">&nbsp;' . Yii::t('app', 'Test') . '</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']
        ],
           
// generated by schmunk42\giiant\generators\crud\providers\RelationProvider::columnFormat
           
[
               
'class' => yii\grid\DataColumn::className(),
               
'attribute' => 'test_id',
               
'value' => function ($model) {
                    if (
$rel = $model->getTest()->one()) {
                        return
Html::a($rel->name, ['test/view', 'id' => $rel->id,], ['data-pjax' => 0]);
                    } else {
                        return
'';
                    }
                },
               
'format' => 'raw',
            ],
           
'phone',
           
'email:email',
        ],
        ]);
?>
</div>

</div>


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