123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace rss\controllers;
- use Yii;
- use yii\data\ArrayDataProvider;
- use yii\web\Controller;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
- /**
- * ListController implements the CRUD actions
- */
- class ListController extends Controller
- {
- /**
- * {@inheritdoc}
- */
- public function behaviors()
- {
- $behaviors = [
- 'verbs' => [
- 'class' => VerbFilter::class,
- 'actions' => [
- 'index' => ['get'],
- ],
- ],
- 'access' => [
- 'class' => AccessControl::class,
- 'rules' => [
- [
- 'roles' => ['admin'],
- 'allow' => true
- ],
- ],
- ],
- ];
- // If auth manager not configured use default access control
- if(!Yii::$app->authManager) {
- $behaviors['access'] = [
- 'class' => AccessControl::class,
- 'rules' => [
- [
- 'roles' => ['@'],
- 'allow' => true
- ],
- ]
- ];
- }
- return $behaviors;
- }
- /**
- * Lists all turbo-pages.
- * @return mixed
- */
- public function actionIndex()
- {
- $module = $this->module;
- $dataProvider = new ArrayDataProvider([
- 'allModels' => $module->getTurboItems()
- ]);
- return $this->render('index', [
- 'module' => $module,
- 'dataProvider' => $dataProvider
- ]);
- }
- /**
- * Clear turbo-pages cache
- *
- * @return mixed
- */
- public function actionClear()
- {
- if ($cache = Yii::$app->getCache()) {
- if ($cache->delete(md5('yandex-turbo'))) {
- Yii::$app->getSession()->setFlash(
- 'success',
- Yii::t('app/modules/turbo', 'Turbo-pages cache has been successfully flushing!')
- );
- } else {
- Yii::$app->getSession()->setFlash(
- 'danger',
- Yii::t('app/modules/turbo', 'An error occurred while flushing the turbo-pages cache.')
- );
- }
- } else {
- Yii::$app->getSession()->setFlash(
- 'warning',
- Yii::t('app/modules/turbo', 'Error! Cache component not configured in the application.')
- );
- }
- return $this->redirect(['list/index']);
- }
- }
|