yii\rest\OptionsAction::run PHP Method

run() public method

Responds to the OPTIONS request.
public run ( string $id = null )
$id string
    public function run($id = null)
    {
        if (Yii::$app->getRequest()->getMethod() !== 'OPTIONS') {
            Yii::$app->getResponse()->setStatusCode(405);
        }
        $options = $id === null ? $this->collectionOptions : $this->resourceOptions;
        Yii::$app->getResponse()->getHeaders()->set('Allow', implode(', ', $options));
    }

Usage Example

 /**
  * Responds to the OPTIONS request.
  *
  * @param $id
  */
 public function actionOptions($id = null)
 {
     $action = new OptionsAction($this->action->id, $this->id);
     $action->resourceOptions = ['GET', 'DELETE', 'HEAD', 'OPTIONS'];
     // array the HTTP verbs that are supported by the resource URL
     $action->run($id);
 }
OptionsAction