Lucky Numbers
Showing 21-27 of 27 items.
# | Number | Color | Created At | Updated At | Created By | Updated By | |
---|---|---|---|---|---|---|---|
21 | 149 | #c267b4 | 2020-07-05 19:28:21 | 2020-07-05 19:28:21 | alice | alice | |
22 | 567 | #c27291 | 2021-02-11 23:58:59 | 2021-02-11 23:59:10 | alice | alice | |
23 | 33 | #c28836 | 2021-11-09 18:28:56 | 2021-11-09 18:28:56 | amy | amy | |
24 | 1212 | #c29e4a | 2021-04-25 20:50:12 | 2021-04-25 20:50:12 | amy | amy | |
25 | 31415 | #db7db7 | 2020-08-25 19:54:23 | 2020-08-25 19:54:23 | alice | alice | |
26 | 7 | #e83120 | 2019-05-07 16:03:42 | 2021-11-21 22:57:43 | ed | pam | |
27 | 69 | #ff3700 | 2020-08-19 12:12:22 | 2020-08-19 12:12:22 | 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') ] ], ], // ... ]); ?>