public function actionSave() { if (Yii::$app->user->can('updateResource')) { $post = Yii::$app->request->post('Chipset'); if ($post['id']) { $model = Chipset::findOne(['id' => $post['id']]); $model->attributes = $post; if ($model->validate()) { if ($model->update()) { Yii::$app->getSession()->setFlash('success', 'Chipset #' . $post['id'] . ' updated.'); } else { Yii::$app->getSession()->setFlash('error', 'Failed to update chipset #' . $post['id'] . '.'); } } } } else { Yii::$app->getSession()->setFlash('error', 'Not allowed.'); } return $this->redirect(['index']); }
<?php use yii\grid\GridView; use yii\data\ActiveDataProvider; use common\models\Chipset; /* @var $this yii\web\View */ $this->title = 'Chipsets'; $this->params['breadcrumbs'][] = $this->title; $dataProvider = new ActiveDataProvider(['query' => Chipset::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'], 'value', ['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>
/** * @return \yii\db\ActiveQuery */ public function getChipset() { return $this->hasOne(Chipset::className(), ['id' => 'chipset_id']); }