V
V
vitaly_742019-04-19 15:57:48
Yii
vitaly_74, 2019-04-19 15:57:48

How to properly set up URL manager in Yii2?

Good afternoon, there is a backend called admin
url-manager with the following configuration:

'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => true,
            'rules' => [
               ''=>"site/index",
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                '/<action:\w+>'=>'site/<action>',
            ],
        ],

the problem is that when you go to tt.ru/admin/users, you need to throw it in tt.ru/admin/users/all - how to do this?
tried this: but '/users'=>'//' doesn't work,
writes 404

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vitaly_74, 2019-04-19
@vitaly_74

Found a solution like this:

'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
               ''=>'site/index',
                '/<action:users>'=>'users/all',
                '/<action>'=>'site/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ],

but you can also use redirects (which seems more correct to me)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question