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