国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

? PHP ????? YII Yii2 API ????? ?? ?? Json ? jsonp ?? ??

Yii2 API ????? ?? ?? Json ? jsonp ?? ??

Nov 01, 2019 pm 04:00 PM
api yii2

Yii2 API ????? ?? ?? Json ? jsonp ?? ??

?? ?? ???? ?????? ??? ? ??? ?? json ?? jsonp ??? ??? ??? ??? ?? ???? json ??? ??? ?? ??? ??? ??? ???? ???? ?? ?? ??? ???? ???.

1 beforeSend? ???? ?? ????? ???. beforesend? ?? ?? ??? ???? ?????. ??? ??? ?? ?????.

/**
 * (non-PHPdoc)
 * @see \yii\base\Object::init()
 */
public function init()
{       
    parent::init();	//綁定beforeSend事件,更改數(shù)據(jù)輸出格式
    Yii::$app->getResponse()->on(Response::EVENT_BEFORE_SEND, [$this, 'beforeSend']);
}
#???? #

2. ?? ?? ?? ?? ???? ???. ?? ???? ??? ?? ?? ??? ????.

1>??? ?? ?? ??

2>????? Json ???? ?????

3> ????? ?? ? $_GET['callback'] ????? ???? Jsonp ??? ?????

# ????#4> ??? ??? ?? ???? {"success":true,"data":{...}}

5>?? ??? ??? ?? ???? { "??":false,"???":{"??": "?? ? ??","message":"???? ?? ? ????.","code":0,"status":404}}

#?? ??#6>???? ??? ??? ????:

/**
     * 更改數(shù)據(jù)輸出格式
     * 默認(rèn)情況下輸出Json數(shù)據(jù)
     * 如果客戶端請(qǐng)求時(shí)有傳遞$_GET['callback']參數(shù),輸入Jsonp格式
     * 請(qǐng)求正確時(shí)數(shù)據(jù)為  {"success":true,"data":{...}}
     * 請(qǐng)求錯(cuò)誤時(shí)數(shù)據(jù)為  {"success":false,"data":{"name":"Not Found","message":"頁(yè)面未找到。","code":0,"status":404}}
     * @param \yii\base\Event $event
     */
    public function beforeSend($event)
    {        /* @var $response \yii\web\Response */
        $response = $event->sender;
        $isSuccessful = $response->isSuccessful;        if ($response->statusCode>=400) {            //異常處理
            if (true && $exception = Yii::$app->getErrorHandler()->exception) {
                $response->data = $this->convertExceptionToArray($exception);
            }            //Model出錯(cuò)了
            if ($response->statusCode==422) {
                $messages=[];                foreach ($response->data as $v) {
                    $messages[] = $v['message'];
                }                //請(qǐng)求錯(cuò)誤時(shí)數(shù)據(jù)為  {"success":false,"data":{"name":"Not Found","message":"頁(yè)面未找到。","code":0,"status":404}}
                $response->data = [                    'name'=> 'valide error',                    'message'=> implode("  ", $messages),                    'info'=>$response->data
                ];
            }
            $response->statusCode = 200;
        }        elseif ($response->statusCode>=300) {
            $response->statusCode = 200;
            $response->data = $this->convertExceptionToArray(new ForbiddenHttpException(Yii::t('yii', 'Login Required')));
        }        //請(qǐng)求正確時(shí)數(shù)據(jù)為  {"success":true,"data":{...}}
        $response->data = [            'success' => $isSuccessful,            'data' => $response->data,
        ];
        $response->format = Response::FORMAT_JSON;
        \Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Origin', '*');
        \Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Credentials', 'true');       //jsonp 格式輸出
        if (isset($_GET['callback'])) {
            $response->format = Response::FORMAT_JSONP;
            $response->data = [                'callback' => $_GET['callback'],                'data'=>$response->data,
            ];
        }
    }
#?? ??#

3. ?? ??? ?? ???? ?? ??? ??? ? ??? ?? ?? ???? ???? ???. ???? ??? ??? ????:

/**
     * 將異常轉(zhuǎn)換為array輸出
     * @see \yii\web\ErrorHandle
     * @param \Exception $exception
     * @return multitype:string NULL Ambigous <string, \yii\base\string> \yii\web\integer \yii\db\array multitype:string NULL Ambigous <string, \yii\base\string> \yii\web\integer \yii\db\array
     */
    protected function convertExceptionToArray($exception)
    {        if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
            $exception = new HttpException(500, Yii::t(&#39;yii&#39;, &#39;An internal server error occurred.&#39;));
        }
        $array = [            &#39;name&#39; => ($exception instanceof Exception || $exception instanceof ErrorException) ? $exception->getName() : &#39;Exception&#39;,            &#39;message&#39; => $exception->getMessage(),            &#39;code&#39; => $exception->getCode(),
        ];        if ($exception instanceof HttpException) {
            $array[&#39;status&#39;] = $exception->statusCode;
        }        if (YII_DEBUG) {
            $array[&#39;type&#39;] = get_class($exception);            if (!$exception instanceof UserException) {
                $array[&#39;file&#39;] = $exception->getFile();
                $array[&#39;line&#39;] = $exception->getLine();
                $array[&#39;stack-trace&#39;] = explode("\n", $exception->getTraceAsString());                if ($exception instanceof \yii\db\Exception) {
                    $array[&#39;error-info&#39;] = $exception->errorInfo;
                }
            }
        }        if (($prev = $exception->getPrevious()) !== null) {
            $array[&#39;previous&#39;] = $this->convertExceptionToArray($prev);
        }        return $array;
    }
#???? #??, ?? ??? ??? ???? ??? ?? API ?????? ???? ?????? ???? ???? ???? ?? ??? ?? ??? ??? ????. # ????#

??: "#?? ??#Yii2.0 ????? ?? ?? ??? ????

? ??? Yii2 API ????? ?? ?? Json ? jsonp ?? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1601
29
PHP ????
1502
276
???
Oracle API ?? ???: ??? ????? ?? ?? Oracle API ?? ???: ??? ????? ?? ?? Mar 07, 2024 am 11:12 AM

Oracle? ????? ??? ?????? ?? ??? ??????, Oracle? API(?? ????? ?????)? ???? Oracle ??????? ?? ?? ???? ???? ? ??? ?? ??? ?????. ? ????? Oracle API ?? ???? ??? ???? ????? ?? ???? ?? ??? ????? ??? ???? ??? ???? ???? ?? ??? ?????. 1.???

PHP ?????? API ?????? ???? ???? ????? ???? ??? ?????? PHP ?????? API ?????? ???? ???? ????? ???? ??? ?????? Sep 05, 2023 am 08:41 AM

PHP ?????? API ?????? ???? ???? ????? ???? ??? ?????? 1. ?? PHP ??????? ?? ?? ?????? ???? ????? ??? ???? ???? ???. ?? ??????? API ?????? ????, ??? ??? ?????? ???? ???? ?? ? ????. ? ????? PHP? ???? API ?????? ???? ???? ????? ???? ??? ?????. 2. API ?????? URL? ????? ?????. ???? ?? ?? API ?????? URL? ?? ????? ??? ???.

?? ??: API ??? ?? ThinkPHP ?????? ???? ?? ?? ??: API ??? ?? ThinkPHP ?????? ???? ?? Nov 22, 2023 pm 05:18 PM

?? ??: API ??? ?? ThinkPHP ?????? ???? ?? ???? ????? ????? API(?? ????? ?????)? ???? ?? ? ??? ????. API? ??? ??, ?? ?? ? ?? ??? ??? ? ??? ????? ??? ???? ?? ?? ??? ?????. ??? PHP ?? ?????? ThinkPHP ?????? ????? ?? ???? ???? ????.

Oracle API ?? ?? ??: ??? ? ??? ?? ?? Oracle API ?? ?? ??: ??? ? ??? ?? ?? Mar 07, 2024 pm 10:09 PM

Oracle API ?? ?? ??: ??? ?? ??? ??? ???? ?? ?? ??? ?????. ??? ??? ??? ?? ?? ???? ?? ???? ???? ???? ?? Oracle API? ??? ??? ?? ??? ?? ? ?????. ??? ? ??. ? ????? OracleAPI? ?? ??? ???? ???? API ?? ??? ???? ????? ??? OracleAPI? ? ? ???? ??? ? ??? ???? ?? ??? ?????. 1. ?? ??? API

Laravel API ?? ??? ???? ?? Laravel API ?? ??? ???? ?? Mar 06, 2024 pm 05:18 PM

??: Laravel API ?? ?? ?? ??, ???? ?? ??? ?????. Laravel? ???? ?? API ??? ?? ?????. ??? ??? ???? ?? ?? ??, ?????? ?? ??, ?? API ?? ?? ? ??? ??? ?? ??? ? ????. ??? ?? ???? ???? ??? ?? ?????. ? ????? Laravel API ?? ???? ????? ???? ??? ???? ?? ?? ?? ??? ?????. 1. Laravel? ?? ??

React API ?? ???: ??? API? ?????? ???? ???? ?? React API ?? ???: ??? API? ?????? ???? ???? ?? Sep 26, 2023 am 10:19 AM

ReactAPI ?? ???: ??? API? ?? ???? ???? ???? ?? ??: ?? ? ????? ??? API? ?? ???? ???? ???? ?? ???? ?? ?????. ?? ???? ????? ?????? React? ? ????? ????? ? ?? ??? ??? ??? ?????. ? ????? React? ???? ?? GET ? POST ??? ???? ??? API? ???? ??? ???? ???? ?? ??? ?????. ??? ???? ??????. ?? Axi? ????? ???? ??? ??????.

??? ????: PHP API ????? ?? ?? ??? ????: PHP API ????? ?? ?? Jan 22, 2024 am 11:21 AM

PHP API ?????: Insomnia ?? ?? Insomnia? ???? API ?????? ??? ?? ????? ???? ? ??? ???. PHP? ??? ?? ????? ??? ????? ?????. ? ????? Insomnia? ???? PHPAPI ?????? ????? ??? ?????. 1??: Insomnia ?? Insomnia? Windows, MacOS ? Linux? ???? ??? ??? ?????????.

PHP API ?????: ???? ??? PHP API ?????: ???? ??? Aug 25, 2023 am 11:45 AM

PHP? ? ??????? ? ???? ???? ? ???? ?? ???? ?? ? ???? ?????. ??? ??? API ?????? ?? ??? ? ??? ?? ???? ?? ?? ?????. ? ????? ???? PHP API ?????? ? ?? ???? ??? ?? ? ??? PHP API ?????? ?? ?? ???? ?????. API? ?????? API? "?????? ????? ?????"? ???, ?? ?? ??????? ?? ???? ??? ??? ? ??? ?? ???? ?????. ? ?? ??? W? ????? ???? ??????.

See all articles