Answer the question
In order to leave comments, you need to log in
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
you can write rules UrlManager in the controller
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 questionAsk a Question
731 491 924 answers to any question