1

I have been setting up REST on Yii2 for two days already, and due to different issues and lack of details in documentation I haven't reach my goals yet.

For now I need to make pluralize working for my controller. I can get all users by requesting GET to my

virtualhost/user,

but 404 for:

virtualhost/users,

virtualhost/user/1,

virtualhost/users/1.

I have UserController.php made by (official documentation):

<?php
namespace app\controllers;

use yii\rest\ActiveController;

class UserController extends ActiveController
{
    public $modelClass = 'app\models\User';
}

I have autogenerated model User, and I have rules, almost the same as in the same quick official guide:

...
'urlManager' => [
    'enablePrettyUrl' => true,
    'enableStrictParsing' => false,
    'showScriptName' => false,
    'rules' => [       
        ['class' => 'yii\rest\UrlRule', 'controller' => 'User'],
    ],
]
....

I have tried to set pluralize property to true, I even checked, does my yii\rest\UrlRule working at all - seems it does not, var_dumps in its init() shows nothing.

I would appreciate any help.

Community
  • 1
  • 1
Bandydan
  • 623
  • 1
  • 8
  • 24
  • 1
    Do you setup `.htaccess` correctly? I've setup REST with default models a few days ago on 2.0.7 it's all works right. – SiZE Mar 05 '16 at 18:07
  • I did, thanks. I have posted the right answer below, and I am so unhappy that there was no errors... – Bandydan Mar 06 '16 at 07:31

1 Answers1

0

I have found the answer. The problem was in controller naming. It is called User, but should be mentioned in rules like 'user', lowercase. I don't know why does developers haven't added any warnings or errors on that thing.

Bandydan
  • 623
  • 1
  • 8
  • 24