Yii\rest\urlrule And Model Names

Hi everyone,

I’m trying to use yii\rest\UrlRule but I cannot understand how I should handle model names.

Suppose I’ve got the following example models:

  • Lorem

  • LoremIpsum

I add the rules for the controller in this way:

'rules' => [

    ['class' => 'yii\rest\UrlRule', 'pluralize' => false, 'controller' => ['lorem', 'loremIpsum']],



[*]Lorem is working correctly, however LoremIpsum is not working. What am I doing wrong? How should I type the controller name in the urlRule to make it work?

[*]What will happen if I removed the ‘pluralize’ => false?


Many thanks

By default recommended convention controller should be named in singular form, for example, PostController.

Pluralize option automatically converts all url rules to plural form so you can access controller actions by

including ‘posts’ in url.

You can read more about that in official documentation here.

To disable this behavior, just set ‘pluralize’ to false as you mentioned in your code snippet. After that you can access controller actions by including ‘post’ in url.

I think the problem is that you try to access controller actions something like ‘loremIpsum’ or ‘loremIpsums’. It should be ‘lorem-ipsums’ because complex camelCase controller action names automatically transformed to url names with dashes.

So try ‘lorem-ipsums’ (or ‘lorem-ipsum’ if ‘pluralize’ option was set to false) and see if it works.