Lucky Numbers

Showing 1-18 of 18 items.
#NumberColorCreated AtUpdated AtCreated ByUpdated By 
17#0f94002019-05-07 16:03:422020-01-16 15:46:08edalice
255#38ab7b2019-05-07 16:07:092020-07-09 15:41:12amyamy
31792#0704c22019-05-07 16:12:352019-05-07 16:57:27alicepam
42019#0499122019-05-07 16:56:432019-05-12 12:17:45pamwendy
55#b51d362019-05-12 12:17:172020-08-19 12:10:40wendyalice
62665#bbb4c22020-02-01 04:29:342020-02-01 04:29:34eded
72#762bc22020-04-04 09:28:082020-04-04 09:28:08alicealice
86#756b4b2020-04-19 18:42:532020-04-19 18:42:53eded
90#0c15c22020-05-05 22:55:552020-05-05 22:55:55alicealice
1014#3d44ff2020-05-11 21:27:262020-05-11 21:27:26alicealice
114523#bcb6c22020-05-13 17:49:112020-05-13 17:49:11alicealice
12149#c267b42020-07-05 19:28:212020-07-05 19:28:21alicealice
13546#8ab1c22020-07-13 00:02:472020-07-13 00:02:47amyamy
1469#ff37002020-08-19 12:12:222020-08-19 12:12:22alicealice
1531415#db7db72020-08-25 19:54:232020-08-25 19:54:23alicealice
164#0c15c22020-10-26 14:57:362020-10-26 14:57:36alicealice
1730#6f83c22020-11-01 04:06:002020-11-01 04:06:00alicealice
18666#0c15c22020-11-03 09:10:262020-11-03 09:10:26amyamy
<?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')
            ]
        ],
    ],
    // ...
]); ?>