yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

GroupUrlRule fails on 2.0.45 #19329

Closed nilsburg closed 2 years ago

nilsburg commented 2 years ago

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.

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 commented 2 years ago

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

bizley commented 2 years ago

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

nilsburg commented 2 years ago

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.