I
I
Igorrebega2014-10-25 13:45:39
Yii
Igorrebega, 2014-10-25 13:45:39

Yii2: how to set a module in defaultRoute?

It is necessary that by default the page with authorization opens.
If you write defaultRoute = 'user/login'
(user - module) - then the error is:

Unable to resolve the request "".

But if site/index, for example, is written, then everything is fine.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valentine, 2014-10-25
@Igorrebega

$config = [
  // ...
  'defaultRoute' => '/модуль/контроллер_модуля/нужный_action',
  // ...
];

S
Sergey, 2014-10-25
@TsarS

In general, if I'm not mistaken, then this is resolved by the filters of the controllers. In site/index put

public function behaviors() {
        return [
                 'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'allow' => true,
                        'actions' => ['index', какие-то еще методы],
                        'roles' => [ '@']
                    ],
                    [
                        'allow' => true,
                        'actions' => ['index'],
                        'roles' => ['@']
                    ],
                    [
                        'allow' => false
                    ]
                ]
            ]
        ];
    }

Well, in each controller, which should be for registered otherwise, everything will still be available via a direct link. Or I misunderstood the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question