Lucky Numbers
Showing 21-27 of 27 items.
# | Number | Color | Created At | Updated At | Created By | Updated By | |
---|---|---|---|---|---|---|---|
21 | 14 | #3d44ff | 2020-05-11 21:27:26 | 2020-05-11 21:27:26 | alice | alice | |
22 | 55 | #38ab7b | 2019-05-07 16:07:09 | 2020-07-09 15:41:12 | amy | amy | |
23 | 0 | #0c15c2 | 2020-05-05 22:55:55 | 2020-05-05 22:55:55 | alice | alice | |
24 | 666 | #0c15c2 | 2020-11-03 09:10:26 | 2020-11-03 09:10:26 | amy | amy | |
25 | 4 | #0c15c2 | 2020-10-26 14:57:36 | 2020-10-26 14:57:36 | alice | alice | |
26 | 1792 | #0704c2 | 2019-05-07 16:12:35 | 2019-05-07 16:57:27 | alice | pam | |
27 | 2019 | #049912 | 2019-05-07 16:56:43 | 2019-05-12 12:17:45 | pam | wendy |
Controller code
<?php use ... class LuckyNumberController extends Controller { public function behaviors() { return [ 'access' => [ 'class' => AccessControl::class, 'only' => ['view', 'create', 'delete'], 'rules' => [ [ 'actions' => ['view'], 'allow' => true, 'roles' => ['@'] // allow all authenticated users ], [ 'actions' => ['create'], 'allow' => true, 'permissions' => ['createItem'] ], [ 'actions' => ['delete'], 'allow' => true, 'permissions' => ['deleteItem'] ], ] ], // ... more behaviors ... ]; // ... actionIndex(), actionView() ... public function actionUpdate($id) { $model = $this->findModel($id); if (! Yii::$app->user->can('updateItem', $model)) { throw new ForbiddenHttpException('Sorry, you\'re not allowed to update this Lucky Number'); } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } return $this->render('update', [ 'model' => $model, ]); } // ... } }
View code
... <?php if (Yii::$app->user->can('createItem')): ?> <p><?= Html::a(Yii::t('app', 'New Lucky Number'), ['create'], ['class' => 'btn btn-outline-success']) ?></p> <?php endif; ?> ... <?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'number', // ... 'updatedBy.name', [ 'class' => 'yii\grid\ActionColumn', 'visibleButtons' => [ 'view' => ! Yii::$app->user->isGuest, 'update' => function ($model, $key, $index) { return Yii::$app->user->can('updateItem', $model); }, 'delete' => Yii::$app->user->can('deleteItem') ] ], ], // ... ]); ?>