Lucky Numbers

Showing 1-20 of 27 items.
#NumberColorCreated AtUpdated AtCreated ByUpdated By 
165535#7e35872021-07-19 12:22:442021-07-19 12:22:44eded
231415#db7db72020-08-25 19:54:232020-08-25 19:54:23alicealice
34523#bcb6c22020-05-13 17:49:112020-05-13 17:49:11alicealice
42665#bbb4c22020-02-01 04:29:342020-02-01 04:29:34eded
52019#0499122019-05-07 16:56:432019-05-12 12:17:45pamwendy
61792#0704c22019-05-07 16:12:352019-05-07 16:57:27alicepam
71212#c29e4a2021-04-25 20:50:122021-04-25 20:50:12amyamy
8666#0c15c22020-11-03 09:10:262020-11-03 09:10:26amyamy
9666#c233312020-12-10 17:01:112020-12-10 17:01:11alicealice
10567#c272912021-02-11 23:58:592021-02-11 23:59:10alicealice
11547#8ab1c22020-07-13 00:02:472021-10-12 16:12:20amyalice
12313#53c27a2022-02-25 21:20:362022-02-25 21:20:36alicealice
13149#c267b42020-07-05 19:28:212020-07-05 19:28:21alicealice
1469#ff37002020-08-19 12:12:222020-08-19 12:12:22alicealice
1555#38ab7b2019-05-07 16:07:092020-07-09 15:41:12amyamy
1633#c288362021-11-09 18:28:562021-11-09 18:28:56amyamy
1730#6f83c22020-11-01 04:06:002020-11-01 04:06:00alicealice
1822#a800c22022-04-18 16:38:052022-04-18 16:38:05alicealice
1914#3d44ff2020-05-11 21:27:262020-05-11 21:27:26alicealice
207#e831202019-05-07 16:03:422021-11-21 22:57:43edpam
<?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')
            ]
        ],
    ],
    // ...
]); ?>