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