Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...