Kohana ORM 序列化列、JSON 和 stdClass
我想知道人们如何处理在 Kohana 的 ORM 中的 _serialize_columns
中的列上运行 json_decode 所产生的 stdClass。
我遇到的问题是我将列设置为数组,该数组已序列化并且一切都很好。后来,当我检索它时,它作为 stdClass 返回。这对于大多数事情来说都是好事,但是如果我尝试在该值上使用诸如 Arr::path()
之类的东西,它当然无法处理(array_shift
的问题)代码>我认为)。
我尝试的一个选项是将结果值转换为数组,但这仅适用于数组的第一级。因此,我然后循环遍历数组,将所有内容都转换为数组。这确实有效,但看起来像是一个相当大的黑客攻击。
其他人都在做什么来处理这个问题?
I'm wondering how people are dealing with the stdClass that results from json_decode run on the columns in _serialize_columns
in Kohana's ORM.
The problem I'm having is that I set the column as an array, which is serialized and is all good. Later, when I retrieve it, it comes back as a stdClass. This is all good for most things, but if I attempt use something like Arr::path()
on that value, it of course can't deal with (a problem with array_shift
I think).
One option I tried was casting the resulting value to an array, but this only works for the first level of the array. So, I then looped through the array casting everything to an array. This worked, but seems like a considerable hack.
What is everyone else doing to deal with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 @zeelot 的推荐,我在 Kohana 的票务系统中提交了一张票证: http://dev.kohanaframework.org /issues/4188
我还重写了 Kohana_ORM 方法
_unserialize_value()
如下:相关讨论在这里:http://forum.kohanaframework.org/discussion/9465/orm -serialize-columns-json-and-stdclass
As a recommendation from @zeelot, I filed a ticket in Kohana's ticketing system: http://dev.kohanaframework.org/issues/4188
I also overrode the Kohana_ORM method
_unserialize_value()
as follows:Related discussion here: http://forum.kohanaframework.org/discussion/9465/orm-serialize-columns-json-and-stdclass