Blame view

app-api/controllers/BaseController.php 1.4 KB
cfe42223   曹明   提交初始代码
1
2
3
4
<?php

namespace app\api\controllers;

200040c1   xu   app-api
5

cfe42223   曹明   提交初始代码
6
7
8
use Yii;
use yii\rest\Controller as RestController;
use yii\filters\ContentNegotiator;
cfe42223   曹明   提交初始代码
9
10
use yii\web\Response;
use yii\filters\VerbFilter;
200040c1   xu   app-api
11
use common\helpers\Log as AppLog;
abb310b5   xu   删除冗余的代码
12
13
14
15
use function str_replace;
use function json_encode;
use function explode;

cfe42223   曹明   提交初始代码
16

cfe42223   曹明   提交初始代码
17
18
19
20
21
22
class BaseController extends RestController
{
    /** @var \yii\web\request **/
    public $request;
    /** @var \yii\web\response **/
    public $response;
abb310b5   xu   删除冗余的代码
23
    /** @var \yii\web\User **/
abb310b5   xu   删除冗余的代码
24

200040c1   xu   app-api
25
26
27
28
29
30
31
32
33
    const LOG_DEBUG = true;

    public function myBaseLog($str)
    {
        if (!LOG_DEBUG) {
            return false;
        }
        AppLog::DEBUG($str);
    }
cfe42223   曹明   提交初始代码
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

    /** @inheritdoc **/
    public function behaviors()
    {
        return [
            'contentNegotiator' => [
                'class' => ContentNegotiator::className(),
                'formats' => [
                    'application/json' => Response::FORMAT_JSON
                ],
            ],
            'verbFilter' => [
                'class' => VerbFilter::className(),
                'actions' => $this->verbs(),
            ],
cfe42223   曹明   提交初始代码
49

f10a8ca1   xu   1. F API 授权接口调整
50
        ];
cfe42223   曹明   提交初始代码
51
52
    }

200040c1   xu   app-api
53
54
55
56
57
58
59
60
61
62
    /**
     * @return string
     */
    public function postData($actionId)
    {
        $getPostData = file_get_contents('php://input', 'r');
        if (!$actionId) {
            $actionId = $this->getRoute();
        }
        $this->myBaseLog($actionId.':'. $getPostData);
abb310b5   xu   删除冗余的代码
63

200040c1   xu   app-api
64
65
        return $getPostData;
    }
cfe42223   曹明   提交初始代码
66

cfe42223   曹明   提交初始代码
67
}