D
D
devilsD2020-01-29 08:24:53
Yii
devilsD, 2020-01-29 08:24:53

How to solve problem with ActiveController in yii2 doesn't resolve options method?

There is a standard controller inherited from ActiveController;
URLManager:

'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => false,
            'showScriptName' => false,
            'rules' => [
                ['class' => 'yii\rest\UrlRule', 'controller' => 'user-product'],
            ],
        ],


GET request to /api/user-products then works correctly.
But the OPTIONS request returns 405 Method Not Allowed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2020-01-29
@devilsD

Derivate from it and override the method:

/**
* {@inheritdoc}
*/
protected function verbs()
{
    return [
        'index' => ['GET', 'HEAD', 'options'],
        'view' => ['GET', 'HEAD'],
        'create' => ['POST'],
        'update' => ['PUT', 'PATCH'],
        'delete' => ['DELETE'],
    ];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question