Kohana:如何获取子请求(HMVC)cookie 更改
我使用以下代码在 HMVC 结构中执行子请求:
对“page1”的请求将通过以下代码向“page2”发出子请求:
$request = Request::factory('/page2')
->method(Request::POST)
->post($postData)
->execute();
“page2”中的执行将添加/更改 cookies 的值item by
setcookie('new_var', $newValue);
现在我需要捕获“Page1”中cookie“new_var”的新值。那么我该怎么做呢?
PS:由于一些限制,我必须在cookie中设置“new_var”,因此将其放入会话并不是答案。
==========更新=============
根据zerkms的建议,我做了这样的事情:
$response = Request::factory('/page2')
->method(Request::POST)
->post($postData);
//before
error_log(print_r($response->cookie(), TRUE));
$response->execute();
//after
error_log(print_r($response->cookie(), TRUE));
“之前”和“之后”日志条目的结果都是空数组。 :(
I use the following code to perform sub-request in HMVC structure:
A request to "page1" will make a sub-request to "page2" by the following code:
$request = Request::factory('/page2')
->method(Request::POST)
->post($postData)
->execute();
The execution in "page2" will add / change the value of a cookies item by
setcookie('new_var', $newValue);
Now I need to capture the new value of the cookie "new_var" in "Page1". So how can I do that?
PS: Due to some limitations, I have to set the 'new_var' in cookie, so putting it to session is not an answer.
==========update =============
As suggested by zerkms, I did something like this:
$response = Request::factory('/page2')
->method(Request::POST)
->post($postData);
//before
error_log(print_r($response->cookie(), TRUE));
$response->execute();
//after
error_log(print_r($response->cookie(), TRUE));
the result of the "before" and "after" log entries are both empty array. :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 kohana 中,你最好使用 Response::cookie() 方法。
在这种情况下,您可以使用此方法检索和设置 cookie(即使在同一请求中)
In kohana you'd better used Response::cookie() method.
In this case you can use this method for both retrieving and setting cookies (even in the same request)