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.
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.