为什么 CI_Session 对象中 set_userdata 时索引为零?
我正在尝试设置一个自定义用户数据变量 - 实际上是一个数组。
我根据表单输入查询了MYSQL UserTable,并返回 作为 result_array 的记录。
$this->session->set_userdata( 'Login', $ResultofUserMatch );
userdata 会话变量的转储如下:
[userdata] => Array
(
[session_id] => fda0d4f9a5b90c813b0850fa6e651b20
[ip_address] => aa.bb.cc.dd
[user_agent] => Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100
[last_activity] => 1319892314
[Login] => Array
(
[0] => Array
(
[ID] => 802
[Care Center Name] => george
[w3user] => [email protected]
[w3pass] => george
[w3code] => none
[role] => admin
)
)
)
请注意,包含 Login 数组,但数据位于 INDEX 0 - 所以他们位于 Login[0][role]。
我做错了什么吗?如何使数据“上一级”?
I'm trying to set a custom Userdata variable - actually, an array.
I have queried MYSQL UserTable based on form input, and returned
the record as a result_array.
$this->session->set_userdata( 'Login', $ResultofUserMatch );
The dump of the userdata session variable is as follows:
[userdata] => Array
(
[session_id] => fda0d4f9a5b90c813b0850fa6e651b20
[ip_address] => aa.bb.cc.dd
[user_agent] => Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100
[last_activity] => 1319892314
[Login] => Array
(
[0] => Array
(
[ID] => 802
[Care Center Name] => george
[w3user] => [email protected]
[w3pass] => george
[w3code] => none
[role] => admin
)
)
)
Note that the Login array is contained, but that the data is at INDEX 0 -
so they're at Login[0][role].
Am I doing something wrong? How do I get the data to be 'up one level'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您获取结果集时,您应该调用
$query->row()
而不是$query->result()
,后者将从结果中获取第一行set,result()
返回集合中所有结果的数组。When you get your result set you should call
$query->row()
instead of$query->result()
which will fetch the first row from the result set,result()
returns an array of all results in the set.