Lucky Numbers

Showing 1-20 of 27 items.
#NumberColorCreated AtUpdated AtCreated ByUpdated By 
169#ff37002020-08-19 12:12:222020-08-19 12:12:22alicealice
27#e831202019-05-07 16:03:422021-11-21 22:57:43edpam
331415#db7db72020-08-25 19:54:232020-08-25 19:54:23alicealice
41212#c29e4a2021-04-25 20:50:122021-04-25 20:50:12amyamy
533#c288362021-11-09 18:28:562021-11-09 18:28:56amyamy
6567#c272912021-02-11 23:58:592021-02-11 23:59:10alicealice
7149#c267b42020-07-05 19:28:212020-07-05 19:28:21alicealice
8666#c233312020-12-10 17:01:112020-12-10 17:01:11alicealice
94523#bcb6c22020-05-13 17:49:112020-05-13 17:49:11alicealice
102665#bbb4c22020-02-01 04:29:342020-02-01 04:29:34eded
115#b51d362019-05-12 12:17:172020-08-19 12:10:40wendyalice
1222#a800c22022-04-18 16:38:052022-04-18 16:38:05alicealice
13547#8ab1c22020-07-13 00:02:472021-10-12 16:12:20amyalice
1465535#7e35872021-07-19 12:22:442021-07-19 12:22:44eded
152#762bc22020-04-04 09:28:082020-04-04 09:28:08alicealice
166#756b4b2020-04-19 18:42:532020-04-19 18:42:53eded
1730#6f83c22020-11-01 04:06:002020-11-01 04:06:00alicealice
182#5b612b2021-02-19 07:27:182021-02-19 07:27:28amyamy
19313#53c27a2022-02-25 21:20:362022-02-25 21:20:36alicealice
205#40c2952021-01-01 22:55:242021-01-01 22:55:24alicealice
<?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')
            ]
        ],
    ],
    // ...
]); ?>