Lucky Numbers

Showing 1-20 of 27 items.
#NumberColorCreated AtUpdated AtCreated ByUpdated By 
122#a800c22022-04-18 16:38:052022-04-18 16:38:05alicealice
2313#53c27a2022-02-25 21:20:362022-02-25 21:20:36alicealice
37#e831202019-05-07 16:03:422021-11-21 22:57:43edpam
433#c288362021-11-09 18:28:562021-11-09 18:28:56amyamy
5547#8ab1c22020-07-13 00:02:472021-10-12 16:12:20amyalice
665535#7e35872021-07-19 12:22:442021-07-19 12:22:44eded
71212#c29e4a2021-04-25 20:50:122021-04-25 20:50:12amyamy
82#5b612b2021-02-19 07:27:182021-02-19 07:27:28amyamy
9567#c272912021-02-11 23:58:592021-02-11 23:59:10alicealice
105#40c2952021-01-01 22:55:242021-01-01 22:55:24alicealice
11666#c233312020-12-10 17:01:112020-12-10 17:01:11alicealice
12666#0c15c22020-11-03 09:10:262020-11-03 09:10:26amyamy
1330#6f83c22020-11-01 04:06:002020-11-01 04:06:00alicealice
144#0c15c22020-10-26 14:57:362020-10-26 14:57:36alicealice
1531415#db7db72020-08-25 19:54:232020-08-25 19:54:23alicealice
1669#ff37002020-08-19 12:12:222020-08-19 12:12:22alicealice
175#b51d362019-05-12 12:17:172020-08-19 12:10:40wendyalice
1855#38ab7b2019-05-07 16:07:092020-07-09 15:41:12amyamy
19149#c267b42020-07-05 19:28:212020-07-05 19:28:21alicealice
204523#bcb6c22020-05-13 17:49:112020-05-13 17:49:11alicealice
<?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')
            ]
        ],
    ],
    // ...
]); ?>