1

I am new to Yii2. I am getting used to it slowly. I am using a module to build customer data. I have a customer table. My module name is Customer. My controller name is Customer. Finally my url structure after enabling pretty url is as below.

http://localhost/basic/web/customers/customers
http://localhost/basic/web/customers/customers/create

etc

How do i remove the module name(customer) from the url? I want to make something like this.

 http://localhost/basic/web/customers/
 http://localhost/basic/web/customers/create

My folder structure

Modules

----Customers

------controllers

-----------DefaultController

-----------CustomersController

------Models

-----------Customers

------Views

-----------customers

--------------create

--------------update

...

----Module.php

I dont know how to insert rules in urlManager even after following this: Yii - Hiding module name in URL

'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,           
        'rules' => array(

            '<controller:\w+>/<action:\w+>'=>'module/controller/action',

    ),

1 Answer 1

0

You have all you need is this and take care, you are looking a Yii1 question.

If your module name is called like your controller try that:

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

We want the format to be used in the Url is controller/action.

With <controller:\w+> we "declare" a "variable" called controller with cointains words, and the same with <action:\w+>.

The internally Yii will call <controller>/<controller>/<action>

Remember controller and action are "variables"

If you want call always the same module you will use:

'rules' =>[
        '<controller:\w+>/<action:\w+>'=>'customers/controller/action',
    ],
Sign up to request clarification or add additional context in comments.

1 Comment

I tried it .But it didnt work. Not Found (#404) error.

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.