0
votes

I just create a Basic App schema in Yii 2.

I try to test RESTFull api.

The site is working, by default, but when I change the urlManager

'urlManager' => [
    'enablePrettyUrl' => true,
    'enableStrictParsing' => true,
    'showScriptName' => false,

    'rules' => [
            ['class' => 'yii\rest\UrlRule', 'controller' => 'cliente'],
    ],

],

I only get 404 error.

I lost site/index!!!

Any idea?

2

2 Answers

0
votes

site/index action no longer works because of this setting: 'enableStrictParsing' => true. From $enableStrictParsing documentation:

If strict parsing is enabled, the incoming requested URL must match at least one of the $rules in order to be treated as a valid request. Otherwise, the path info part of the request will be treated as the requested route.

So if you enable this setting, you need to have matching URL rule to support given URL. In your case, you have only one rule for REST endpoint, so any other URL will not work. You should either disable this setting or add rule for your main page:

'rules' => [
    '' => 'site/index',
    ['class' => 'yii\rest\UrlRule', 'controller' => 'cliente'],
],
0
votes

It is this setting: 'enableStrictParsing' => true,

Look here:

https://github.com/yiisoft/yii2/blob/master/framework/web/UrlManager.php#L323

There are no explicit url rules for the siteController defined.

Read more here:

https://www.yiiframework.com/doc/guide/2.0/en/runtime-routing#url-rules