Lucky Numbers

Showing 1-11 of 11 items.
#NumberColorCreated AtUpdated AtCreated ByUpdated By 
114#000d9c2019-05-07 16:07:092019-06-25 21:46:39amyamy
22019#0499122019-05-07 16:56:432019-05-12 12:17:45pamwendy
31792#0704c22019-05-07 16:12:352019-05-07 16:57:27alicepam
41#0c15c22019-05-21 16:58:072019-05-21 16:58:07alicealice
51#0c15c22019-05-21 16:57:502019-05-21 16:57:50alicealice
67#2b2d942019-05-07 16:03:422019-05-07 16:03:42eded
713#3a541f2019-05-07 16:01:302019-05-31 15:50:20amyamy
898#66c2652019-06-01 08:52:542019-06-01 08:53:08alicealice
95#b5b5282019-05-12 12:17:172019-05-12 12:17:17wendywendy
103#c254482019-06-11 06:47:552019-06-11 06:47:55alicealice
112#c2695d2019-05-15 18:27:192019-05-16 23:10:39alicealice
<?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')
            ]
        ],
    ],
    // ...
]); ?>