0

I am new to yii2.

mydomain.com/organisation/banks/index

from above url i want to remove organisation.

i add following code to my config file under component section.

'urlManager' => [
    'showScriptName' => false,
    'enablePrettyUrl' => true,
    'rules' => [
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>'=>'modules/<controller:\w+>/<action:\w+>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ],
]

But still its not working.

Is there any way to do it?

Thanks

2
  • Is the above URL the only one where you need to hide module name? Or are there multiple URLs to hide? Commented Dec 2, 2016 at 6:44
  • there are multiple URLs to hide Commented Dec 2, 2016 at 7:10

1 Answer 1

1

In case of multiple URLs to hide I'm afraid you have to add the rule for each URL like:

'banks/index' => 'organisation/banks/index',
'something/another' => 'organisation/something/another',

If there is an unique controller's name that this module uses you can make it easier by adding general rule. For example if controller's name is banks and there is no BanksController under the top namespace level of app you can add:

'banks/<action>' => 'organisation/banks/<action>',

If organisation module is the only one your app uses and you don't need top namespace level controllers you can add:

'' => 'organisation',

So entering the domain URL address gets you directly to organisation module default route.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks.it solve my problem. but i have more than 5 modules and each modules have more than 10 process(controller) is there any easier way to make it general for all modules?
Why do you need to hide all the modules' names?
its my clinet's requirement
So either you add all the rules one by one or find some way to make general rules for similar groups of URL or create top namespace level controllers that will map module controllers. In every case it's tedious job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.