Difference between the Kohana's Request cookie(), Response cookie() and the Cookie class?

放肆的年华 提交于 2019-12-13 07:49:22

问题


I'm working on a program dealing with cookies under the kohana's HMVC structure, and I find that Kohana has 3 ways to get/set the cookie. They are

Request::current()->cookie(), Response->cookie(), and the cookie class (Cookie::set(), get())

And PHP has a native setcookie() function and $_COOKIE to deal with cookies too.

Could anyone explain their differences and, what are the situations that they should be used respectively.


回答1:


Request::cookie() prior to calling Request::execute() on the same object is used to set the cookies that will be send (or have been sent in case of the initial request) along with the rest of the request. Request::cookie() during a Request::execute() will replace $_COOKIE.

Response::cookie() during a Request::execute() will replace setcookie(). Response::cookie() after a Request::execute() is used to get the cookies set back by the server.

The Cookie helper will sign your cookies and is used by HTTP_Header to set cookies set to the Response object in your initial Request object (see Response::send_headers() in index.php). You probably do not want to use it yourself directly if you are trying to code HMVC safe.



来源:https://stackoverflow.com/questions/7543811/difference-between-the-kohanas-request-cookie-response-cookie-and-the-cook

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!