[英]Laravel 3 flashed variables are not always in the Session
I'm using the following line to redirect to my base index action in a bundle: 我使用以下行重定向到捆绑包中的基本索引操作:
return Redirect::to_action('mybundle::base@index')->with("prevCommands", $prevCommands)->with("result", $result)->with_input();
Redirection works but when I'm grabbing the info from the Session I randomly get null values, the following code is in my index action: 重定向有效,但是当我从会话中获取信息时,我随机获得空值,以下代码在索引操作中:
$view['prevCommands'] = (array)Session::get('prevCommands');
$view['result'] = (string)Session::get('result');
The combination above seems to only randomly work, and it tends to work better if the server takes a bit longer to respond. 上面的组合似乎只能随机工作,并且如果服务器花费更长的时间来响应,则它往往会工作得更好。 I checked that the variables are correctly populated all the time before redirecting.
在重定向之前,我一直检查变量是否正确填充。
When it happens both values come back as null at once. 发生这种情况时,两个值都立即返回为null。 There's never a case where only one of them is set.
在任何情况下都不会只设置其中一个。
It sounds like you're using the cookie session driver, and that it's running out of space. 听起来您正在使用cookie会话驱动程序,并且空间不足。 I'd recommend changing to any of the other drivers (except 'memory').
我建议更改为其他任何驱动程序(“内存”除外)。
Laravel 3 offers a number of session drivers . Laravel 3提供了许多会话驱动程序 。 'cookie' is the default driver as it requires zero set up, but it has a size limit of 4K.
“ cookie”是默认驱动程序,因为它需要设置为零,但是大小限制为4K。 For anything more serious you should consider a different driver.
对于更严重的问题,您应该考虑使用其他驱动程序。 In order of ease of set up...
为了易于设置...
It's worth mentioning the memory driver, this is useful only for testing as the data is not persistent (lost at the end of the request). 值得一提的是内存驱动程序,由于数据不是持久性的(在请求结束时丢失),因此仅对测试有用。
Never mind, I figured it out, it began to make sense once I noticed that the cookie driver for Sessions in Laravel 3 does not actually use PHP's built in Cookie Session mechanism, it actually stores the whole payload in a cookie. 没关系,我想通了,一旦我注意到Laravel 3中Session的cookie驱动程序实际上并没有使用PHP内置的Cookie Session机制,它就开始变得有意义了,它实际上将整个有效负载存储在cookie中。
Since cookies have a limited size allowance this mechanism breaks if the total data stored exceeds 4K, bearing in mind all the "padding" characters for storing an actual array in the session. 由于cookie的大小限制有限,如果存储的总数据超过4K,此机制就会中断,请记住所有用于在会话中存储实际数组的“填充”字符。
This also made me aware that my application's design is faulty, I should not flash such huge amounts of data to the session. 这也让我意识到我的应用程序设计有问题,我不应该将如此大量的数据闪存到会话中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.