Lucky Numbers

Showing 1-20 of 27 items.
#NumberColorCreated AtUpdated AtCreated ByUpdated By 
11792#0704c22019-05-07 16:12:352019-05-07 16:57:27alicepam
22019#0499122019-05-07 16:56:432019-05-12 12:17:45pamwendy
32665#bbb4c22020-02-01 04:29:342020-02-01 04:29:34eded
42#762bc22020-04-04 09:28:082020-04-04 09:28:08alicealice
56#756b4b2020-04-19 18:42:532020-04-19 18:42:53eded
60#0c15c22020-05-05 22:55:552020-05-05 22:55:55alicealice
714#3d44ff2020-05-11 21:27:262020-05-11 21:27:26alicealice
84523#bcb6c22020-05-13 17:49:112020-05-13 17:49:11alicealice
9149#c267b42020-07-05 19:28:212020-07-05 19:28:21alicealice
1055#38ab7b2019-05-07 16:07:092020-07-09 15:41:12amyamy
115#b51d362019-05-12 12:17:172020-08-19 12:10:40wendyalice
1269#ff37002020-08-19 12:12:222020-08-19 12:12:22alicealice
1331415#db7db72020-08-25 19:54:232020-08-25 19:54:23alicealice
144#0c15c22020-10-26 14:57:362020-10-26 14:57:36alicealice
1530#6f83c22020-11-01 04:06:002020-11-01 04:06:00alicealice
16666#0c15c22020-11-03 09:10:262020-11-03 09:10:26amyamy
17666#c233312020-12-10 17:01:112020-12-10 17:01:11alicealice
185#40c2952021-01-01 22:55:242021-01-01 22:55:24alicealice
19567#c272912021-02-11 23:58:592021-02-11 23:59:10alicealice
202#5b612b2021-02-19 07:27:182021-02-19 07:27:28amyamy
<?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,
            ]);
        }
        // ...

    }
}
...
<?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')
            ]
        ],
    ],
    // ...
]); ?>