Lucky Numbers

Showing 21-27 of 27 items.
#NumberColorCreated AtUpdated AtCreated ByUpdated By 
2114#3d44ff2020-05-11 21:27:262020-05-11 21:27:26alicealice
220#0c15c22020-05-05 22:55:552020-05-05 22:55:55alicealice
236#756b4b2020-04-19 18:42:532020-04-19 18:42:53eded
242#762bc22020-04-04 09:28:082020-04-04 09:28:08alicealice
252665#bbb4c22020-02-01 04:29:342020-02-01 04:29:34eded
262019#0499122019-05-07 16:56:432019-05-12 12:17:45pamwendy
271792#0704c22019-05-07 16:12:352019-05-07 16:57:27alicepam
<?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')
            ]
        ],
    ],
    // ...
]); ?>