简体   繁体   中英

Yii routing module problems

This is my module "auth"

-auth/
-controllers/
---AuthController.php

in controller I have action "register"

In layout I create route url:

$this->createUrl('auth/auth/register')

Rules are in config/main.php

'urlManager' => array(
    'urlFormat' => 'path',
    'showScriptName' => false,
    'rules' => array(
        'register' => 'auth/auth/register',
        '<controller:\w+>/<id:\d+>' => '<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
        '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
    ),
),

When I'm in mySite/index.php register url looks well: mySite/register . Url works and view is visible. When I'm this view mySite/register here starts a problem. Register url is mySite/auth/auth/auth/register - of course i see 404 error. Why it apeears and how to solve this problem?

From the API page for createUrl

If the controller belongs to a module, the module ID will be prefixed to the route. (If you do not want the module ID prefix, the route should start with a slash '/'.)

Thus your code should read

$this->createUrl('/auth/auth/register')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM