public function actionSave()
 {
     if (Yii::$app->user->can('updateResource')) {
         $post = Yii::$app->request->post('DeviceType');
         if ($post['id']) {
             $model = DeviceType::findOne(['id' => $post['id']]);
             $model->attributes = $post;
             if ($model->validate()) {
                 if ($model->update()) {
                     Yii::$app->getSession()->setFlash('success', 'Device type #' . $post['id'] . ' updated.');
                 } else {
                     Yii::$app->getSession()->setFlash('error', 'Failed to update device type #' . $post['id'] . '.');
                 }
             }
         }
     } else {
         Yii::$app->getSession()->setFlash('error', 'Not allowed.');
     }
     return $this->redirect(['index']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDeviceType()
 {
     return $this->hasOne(DeviceType::className(), ['id' => 'device_type_id']);
 }
Beispiel #3
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>