-
Notifications
You must be signed in to change notification settings - Fork 36
/
RestController.php
54 lines (35 loc) · 1.2 KB
/
RestController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use app\models\LoginForm;
class RestController extends Controller
{
public $request;
public $enableCsrfValidation = false;
public $headers;
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['corsFilter'] = [
'class' => \yii\filters\Cors::className(),
'cors' => [
'Origin' => ['*'],
// 'Access-Control-Allow-Origin' => ['*', 'http://haikuwebapp.local.com:81','http://localhost:81'],
'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
'Access-Control-Request-Headers' => ['*'],
'Access-Control-Allow-Credentials' => null,
'Access-Control-Max-Age' => 86400,
'Access-Control-Expose-Headers' => []
]
];
return $behaviors;
}
public function init()
{
$this->request = json_decode(file_get_contents('php://input'), true);
if($this->request&&!is_array($this->request)){
Yii::$app->api->sendFailedResponse(['Invalid Json']);
}
}
}