D
D
Dilik Pulatov2017-06-17 23:33:44
Yii
Dilik Pulatov, 2017-06-17 23:33:44

In Yii2 - Urlmanager rules in the controller can be written?

Hello!
is it possible to write rules UrlManager in the controller?
I don’t want to write in the config .... since there are many similar URLs
and in the module how to write my own URL rules?
let's say there is an admin module, they need to write the rules url for this module .... can I write in the module? not in config

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-06-18
@webinar

you can write rules UrlManager in the controller

rules are routing rules. If the control is running, then the rules have already worked. How do you imagine it?
language not recognized, check or translate into Russian
See the first point, the same paradox as with the controller. The url manager rules are exactly what is needed to determine which module and which controller should work. You can't wash your hands and then turn on the faucet.

D
Dmitry, 2017-06-18
@slo_nik

Goodnight.
No.
Create a configuration file for the module, and write there.
Make sure that there are no duplicates and write in the configuration file.
An example rules for a module in a common configuration file:

'rules' => [
                [
                  // правиля для модуля admin
                  'class' => 'yii\web\GroupUrlRule',
                  'prefix' => 'admin',
                  'routePrefix' => 'admin',
                  'rules' => [
                     '<_a:(login|logout)>' => 'user/users/<_a>',
                     '<_m:[\w\-]+>' => '<_m>/default/index',
                     '<_m:[\w\-]+>/<id:\d+>' => '<_m>/default/view',
                     '<_m:[\w\-]+>/<id:\d+>/<_a:[\w\-]+>' => '<_m>/default/<_a>',
                     '<_m:[\w\-]+>/<_c:[\w\-]+>/<id:\d+>' => '<_m>/<_c>/view',
                     '<_m:[\w\-]+>/<_c:[\w\-]+>/<id:\d+>/<_a:[\w\-]+>' => '<_m>/<_c>/<_a>',
                     '<_m:[\w\-]+>/<_c:[\w\-]+>/<_a:[\w\-]+>' => '<_m>/<_c>/<_a>',
                     '<_m:[\w\-]+>/<_c:[\w\-]+>' => '<_m>/<_c>/index',
                  ],
                ],
                // тут rules для остального сайта
            ],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question