yii2 icon indicating copy to clipboard operation
yii2 copied to clipboard

defaultRoute does not work

Open glagola opened this issue 12 years ago • 10 comments

Hi, I have set defaultRoute in my application and enable enableStrictParsing in url Manager component, it seems that they can't work together? If it is true and it isn't a bug, I think, It would be cool to mention that in documentation.

P.S. sorry for my bad English.

glagola avatar Nov 03 '14 19:11 glagola

Reproduced. With

'urlManager' => [
    'enablePrettyUrl' => true,
    'enableStrictParsing' => true,
],

defaultRoute is ignored. The same effect could be achieved by explicitly adding the following to rules:

'' => 'site/index', // default route here

samdark avatar Nov 03 '14 23:11 samdark

@yiisoft/core-developers do you think it should be somehow fixed? If yes, any ideas? If no I think it should be documented in defaultRoute phpdoc.

samdark avatar Nov 03 '14 23:11 samdark

default route does not have anything to do with UrlManager, if you enable strict parsing you have to give a route for every possible Url. if there is none, no URL will be there.

if you add '' => '' as a rule the default route will apply too so this is nothing to be fixed. Not sure if there is a need to clarify something somewhere.

cebe avatar Nov 03 '14 23:11 cebe

See this http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html#default-route

qiangxue avatar Nov 04 '14 01:11 qiangxue

@qiangxue ? The issue is about defaultRoute doesn't work when we're using strictParsing in URL manager.

samdark avatar Nov 04 '14 10:11 samdark

@samdark As explained in the guide, defaultRoute is used when an empty route is resolved from the current request. It has nothing to do with strictParsing.

qiangxue avatar Nov 04 '14 13:11 qiangxue

OK.

samdark avatar Nov 04 '14 13:11 samdark

@qiangxue @samdark I just think that this behaviour is an undocumented feature, not a bug. May be, it should be mentioned in documentation, that defaultRoute would be ignored, when strictParsing is enabled. I think, it wouldn't be obvious for a new user

glagola avatar Nov 04 '14 15:11 glagola

@glagola As I said, defaultRoute has nothing to do with strictParsing. Even if you enable strictParsing, defaultRoute may still be used if a rule resolves the request into an empty route.

qiangxue avatar Nov 04 '14 16:11 qiangxue

@qiangxue Thank you! Such application config works perfectly:

[
    ...
    'defaultRoute' => 'site/login',
    ...
    'urlManager' => [
        'enablePrettyUrl' => true,
        'enableStrictParsing' => true,
        ...
        'rules' => [
            ...
            '' => '',   // <- this line should be added
        ],
    ],
    ...
]

glagola avatar Nov 04 '14 16:11 glagola