Skip to content

Cors ​

Type
Class
Namespace
craft\filters
Inherits
craft\filters\Cors » yii\filters\Cors » yii\base\ActionFilter » yii\base\Behavior » yii\base\BaseObject
Implements
yii\base\Configurable
Uses traits
craft\filters\SiteFilterTrait
Since
5.3.0

Filter for adding CORS headers to site responses and handling OPTIONS requests.

See also https://www.yiiframework.com/doc/api/2.0/yii-filters-cors

View source

Public Properties ​

PropertyDescription
actionsarray – Define specific CORS rules for specific actions
corsarray – Basic headers handled for the CORS requests.
exceptarray – List of action IDs that this filter should not apply to.
onlyarray – List of action IDs that this filter should apply to.
owneryii\base\Component, null – The owner of this behavior
requestyii\web\Request, null – The current request.
responseyii\web\Response, null – The response to be sent.
siteinteger, string, craft\models\Site, `(int

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
addCorsHeaders()Adds the CORS headers to the response.
afterAction()This method is invoked right after an action is executed.
afterFilter()
attach()Attaches the behavior object to the component.
beforeAction()This method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action.
beforeFilter()
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
detach()Detaches the behavior object from the component.
events()Declares event handlers for the owner's events.
extractHeaders()Extract CORS headers from the request.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
overrideDefaultSettings()Override settings for specific action.
prepareHeaders()For each CORS headers create the specific response.

Protected Methods ​

MethodDescription
getActionId()Returns an action ID by converting yii\base\Action::$uniqueId into an ID relative to the module.
headerize()Convert any string (including php headers with HTTP prefix) to header format.
headerizeToPhp()Convert any string (including php headers with HTTP prefix) to header format.
isActive()Returns a value indicating whether the filter is active for the given action.
prepareAllowHeaders()Handle classic CORS request to avoid duplicate code.
setSite()