Lucky Numbers
Showing 1-20 of 27 items.
# | Number | Color | Created At | Updated At | Created By | Updated By | |
---|---|---|---|---|---|---|---|
1 | 2019 | #049912 | 2019-05-07 16:56:43 | 2019-05-12 12:17:45 | pam | wendy | |
2 | 1792 | #0704c2 | 2019-05-07 16:12:35 | 2019-05-07 16:57:27 | alice | pam | |
3 | 666 | #0c15c2 | 2020-11-03 09:10:26 | 2020-11-03 09:10:26 | amy | amy | |
4 | 0 | #0c15c2 | 2020-05-05 22:55:55 | 2020-05-05 22:55:55 | alice | alice | |
5 | 4 | #0c15c2 | 2020-10-26 14:57:36 | 2020-10-26 14:57:36 | alice | alice | |
6 | 55 | #38ab7b | 2019-05-07 16:07:09 | 2020-07-09 15:41:12 | amy | amy | |
7 | 14 | #3d44ff | 2020-05-11 21:27:26 | 2020-05-11 21:27:26 | alice | alice | |
8 | 5 | #40c295 | 2021-01-01 22:55:24 | 2021-01-01 22:55:24 | alice | alice | |
9 | 313 | #53c27a | 2022-02-25 21:20:36 | 2022-02-25 21:20:36 | alice | alice | |
10 | 2 | #5b612b | 2021-02-19 07:27:18 | 2021-02-19 07:27:28 | amy | amy | |
11 | 30 | #6f83c2 | 2020-11-01 04:06:00 | 2020-11-01 04:06:00 | alice | alice | |
12 | 6 | #756b4b | 2020-04-19 18:42:53 | 2020-04-19 18:42:53 | ed | ed | |
13 | 2 | #762bc2 | 2020-04-04 09:28:08 | 2020-04-04 09:28:08 | alice | alice | |
14 | 65535 | #7e3587 | 2021-07-19 12:22:44 | 2021-07-19 12:22:44 | ed | ed | |
15 | 547 | #8ab1c2 | 2020-07-13 00:02:47 | 2021-10-12 16:12:20 | amy | alice | |
16 | 22 | #a800c2 | 2022-04-18 16:38:05 | 2022-04-18 16:38:05 | alice | alice | |
17 | 5 | #b51d36 | 2019-05-12 12:17:17 | 2020-08-19 12:10:40 | wendy | alice | |
18 | 2665 | #bbb4c2 | 2020-02-01 04:29:34 | 2020-02-01 04:29:34 | ed | ed | |
19 | 4523 | #bcb6c2 | 2020-05-13 17:49:11 | 2020-05-13 17:49:11 | alice | alice | |
20 | 666 | #c23331 | 2020-12-10 17:01:11 | 2020-12-10 17:01:11 | alice | alice |
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') ] ], ], // ... ]); ?>