Answer the question
In order to leave comments, you need to log in
Yii2 RETSful API why Method Not Allowed?
The documentation for Yii2 quite clearly states -
GET /users: getting a page-by-page list of all users;
HEAD /users: get user listing metadata;
POST /users: create a new user;
GET /users/123: getting information on a specific user with id equal to 123;
HEAD /users/123: getting metadata for a specific user with id equal to 123;
PATCH /users/123 and PUT /users/123: change information for a user with id equal to 123;
DELETE /users/123: delete user with id equal to 123;
OPTIONS /users: get supported methods by which /users can be accessed;
OPTIONS /users/123: Get supported methods by which to access /users/123.
<?php
namespace app\controllers;
use yii\rest\ActiveController;
/**
* PostController implements the CRUD actions for Posts model.
*/
class PostController extends ActiveController
{
public $modelClass = 'app\models\Posts';
}
?>
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing'=>true,
'rules' => [
'post'=>'post',
'profile'=>'profile/index',
'profile/verify/<hash:\w+>'=>'/auth/verify',
'logout'=>'auth/logout',
'register'=>'auth/register',
['class' => 'yii\rest\UrlRule', 'controller' => 'post'],
],
],
Answer the question
In order to leave comments, you need to log in
Adding a parameter to urlManager helped
['class' => 'yii\rest\UrlRule', 'controller' => 'post', 'pluralize'=>false],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question