コード例 #1
0
<?php

use yii\grid\GridView;
use yii\data\ActiveDataProvider;
use common\models\DeviceType;
/* @var $this yii\web\View */
$this->title = 'Device Types';
$this->params['breadcrumbs'][] = $this->title;
$dataProvider = new ActiveDataProvider(['query' => DeviceType::find(), 'pagination' => ['pageSize' => 20]]);
?>
<div class="box">
  <div class="box-body">

<?php 
if (Yii::$app->user->can('listResources')) {
    echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', ['attribute' => 'created_at', 'format' => ['datetime', 'php:Y-m-d H:i:s']], ['attribute' => 'updated_at', 'format' => ['datetime', 'php:Y-m-d H:i:s']], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update}']]]);
}
?>
  </div>
</div>
コード例 #2
0
 public function actionList()
 {
     echo Json::encode(array_map(function ($m) {
         return $m['name'];
     }, DeviceType::find()->orderBy('name')->all()));
 }