Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroupUrlRule fails on 2.0.45 #19329

Closed
nilsburg opened this issue Mar 29, 2022 · 3 comments
Closed

GroupUrlRule fails on 2.0.45 #19329

nilsburg opened this issue Mar 29, 2022 · 3 comments
Labels
Milestone

Comments

@nilsburg
Copy link

What steps will reproduce the problem?

This problem appears with version 2.0.45. On version 2.0.44 or below it works as expected.

  • Create a new project using yii2-app-basic
  • Install Yii 2.0.45
  • Create a module named 'test', with controller and view
  • Add a GroupUrlRule to load the module:
'urlManager'   => [
            'enablePrettyUrl' => true,
            'showScriptName'  => false,
            'rules'           => [
                new GroupUrlRule([
                    'prefix'      => '/',
                    'routePrefix' => 'test',
                    'rules'       => [
                        '/' => 'default/index',
                    ],
                ]),
            ],
        ],

What is the expected result?

Result from running route test/default/index

What do you get instead?

Result from running route site/index

When downgrading Yii to 2.0.44 it loads test/default/index correctly.

Additional info

config/web.php

<?php

use yii\web\GroupUrlRule;

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';

$config = [
    'id'         => 'basic',
    'basePath'   => dirname(__DIR__),
    'bootstrap'  => ['log'],
    'aliases'    => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'modules'    => [
        'test' => 'app\modules\test\Module',
    ],
    'components' => [
        'request'      => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'abs',
        ],
        'cache'        => [
            'class' => 'yii\caching\FileCache',
        ],
        'user'         => [
            'identityClass'   => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer'       => [
            'class'            => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log'          => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets'    => [
                [
                    'class'  => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'urlManager'   => [
            'enablePrettyUrl' => true,
            'showScriptName'  => false,
            'rules'           => [
                new GroupUrlRule([
                    'prefix'      => '/',
                    'routePrefix' => 'test',
                    'rules'       => [
                        '/' => 'default/index',
                    ],
                ]),
            ],
        ],
        'db'           => $db,
        /*
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
        */
    ],
    'params'     => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;

Module test setup
modules/tests/controllers/DefaultController.php

<?php

namespace app\modules\test\controllers;

class DefaultController extends \yii\web\Controller
{
    public function actionIndex()
    {
        return $this->render('index');
    }
}

modules/tests/views/default/index.php

index
<?php

modules/test/Module.php

<?php

namespace app\modules\test;

class Module extends \yii\base\Module
{

}
Q A
Yii version 2.0.45
PHP version 7.4
Operating system Ubuntu
@WinterSilence
Copy link
Contributor

I don't see error, http://localhost:8888/ - Application::$defaultRoute, http://localhost:8888/test/ - DefaultController(test module)

@bizley
Copy link
Member

bizley commented Mar 29, 2022

Hm, I can see this change made to the GroupUrlRule. Was there a reason to remove /?

@nilsburg
Copy link
Author

Hm, I can see this change made to the GroupUrlRule. Was there a reason to remove /?

I can confirm that changing that line back solves the issue.

@bizley bizley added the type:bug Bug label Mar 29, 2022
@bizley bizley added this to the 2.0.46 milestone Mar 29, 2022
@bizley bizley closed this as completed Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants