Answer the question
In order to leave comments, you need to log in
How to defeat the nasty CORS in Yii?
I am writing a REST application. There is a test controller. AJAX calls to default URLs like 127.0.0.1:8000/tests work fine. I'm trying to add a custom URL. In the controller I create the corresponding action :
public function actionYo()
{ return ['result' => 'YO! Pipol!!!! ']; }
[
'class' => 'yii\rest\UrlRule',
'controller' => 'test',
'extraPatterns' => [
'GET yo' => 'yo', // 'xxxxx' refers to 'actionXxxxx'
//пробовал танцевать с бубном вот так - без толку
// 'OPTIONS yo' => 'yo', // 'xxxxx' refers to 'actionXxxxx'
],
],
$behaviors['corsFilter'] = [
'class' => \yii\filters\Cors::className(),
'cors' => [ // restrict access to domains:
'Origin' => [
'http://localhost:8080',
],
'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Request-Headers' => ['*'],
'Access-Control-Max-Age' => 3600 * 5,
],
];
[
'class' => 'yii\rest\UrlRule',
'controller' => ['test', 'best'], // строчка ОДЫН - здесь все контроллеры, для которых это должно работать
'extraPatterns' => [
//строчка ДЫВА - эта штука будет отправлять все на экшн options, он уже есть в родительском ActiveController
'OPTIONS <action:\w+>' => 'options'
],
],
Answer the question
In order to leave comments, you need to log in
As far as I understand, Yii OPTIONS queries, in general, should resolve on their own.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question