Hi Folks,
I’m probably missing something, but I’ve created a test controller, and implemented actionIndex, actionView, actionUpdate, and actionCreate.
A GET /v2/contacts goes to actionIndex, GET /v2/contacts/{id} goes to actionView($id), PUT /v2/contacts/{id} goes to actionUpdate($id), however a POST to /v2/contacts ends up going to actionIndex, and is then blocked as POST isn’t an allowed verb on actionIndex.
I have created a modules/v2/controllers/APIController which extends yii\rest\Controller, and does:
protect function verbs() {
return [
'index' => ['GET', 'HEAD'],
'view' => ['GET', 'HEAD'],
'create' => ['POST'],
'update' => ['PUT', 'PATCH'],
'delete' => ['DELETE'],
];
}
And then I have a ContactsController which extends it, and implements the various action* functions.
In my config/main.php for api, I have:
'urlManager' => [
'cache' => false,
'rules' => [
[
'class'=> 'yii\rest\UrlRule',
'controller' => [
'v2/contacts',
],
],
],
],
Have I missed something? As I mentioned, everything seems to work EXCEPT the POST. I’ve put 6 hour or so into tracing through the code and so far I’m pulling up blanks.
Thanks,
Damien