Laravel 響應準備

2021-09-17 00:26:01 字數 1912 閱讀 1388

public function prepareresponse($request, $response)

// 若不是 \symfony\component\httpfoundation\symfonyresponse 的物件,則構造成此物件

elseif (! $response instanceof symfonyresponse)

return $response->prepare($request);

}

public function createresponse(responseinte***ce $psrresponse)

return $response;

}本質就是用的 response 類

public function __construct($content = '', $status = 200, $headers = array())

if (isset(self::$deprecationstriggered[$class]))

self::$deprecationstriggered[$class] = true;

foreach (self::$deprecatedmethods as $method)

}}public function setcontent($content)

$this->content = (string) $content;

return $this;

}public function setstatuscode($code, $text = null)

if (null === $text)

if (false === $text)

$this->statustext = $text;

return $this;

}public function isinvalid()

public function setprotocolversion($version)

主要是設定響應頭

public function prepare(request $request)

else

}// 設定編碼格式

$charset = $this->charset ?: 'utf-8';

if (!$headers->has('content-type')) elseif (0 === stripos($headers->get('content-type'), 'text/') && false === stripos($headers->get('content-type'), 'charset'))

// 若傳輸時用分塊編碼,則移除 content-length, 因為採用分塊編碼時可以知道傳輸何時完成

Laravel 傳送響應

若是 fastcgi 模式,則結束客戶端響應後非同步執行伺服器端的後續任務,例如中介軟體的 terminate 方法和事件等 if function exists fastcgi finish request elseif cli php sapi public static function cl...

Laravel配置路由

route get function route get test function 在瀏覽器中輸入192.168.xx.xx,可以看到網頁返回了get hello world,如果沒有返回,重啟以下httpd,apatch伺服器 在瀏覽器中輸入192.168.xx.xx test,如果返回失敗,則...

laravel表單驗證

效果展示 實現 後台 use validator php view plain copy print public function login 使用者驗證 user db table user select user id user encrypt user pwd where user name...