Codeigniter调用非对象上的成员函数set_userdata() [英] Codeigniter Call to a member function set_userdata() on a non-object

查看:91
本文介绍了Codeigniter调用非对象上的成员函数set_userdata()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CI应用程序中遇到一个致命错误,我刚刚从php4共享主机移到了php5共享主机。

I am getting a fatal error in a CI app that I just moved from a php4 shared host to a php5 shared host.

Fatal error: Call to a member function set_userdata() on a non-object in /home/chuck_ravenna/bob.ravennainteractive.com/system/application/helpers/authenticate_helper.php on line 13

位于完整位置的代码在下面的链接中

https:// gist.github.com/1474173

我正在尝试确定php版本是否是问题所在。该网站可以在旧服务器上正常运行,而新服务器没有php4选项。

I am trying to figure out if the php version could be the issue. The site runs fine on the old server, and the new server doesn't have php4 as an option.

断掉的特定代码行是:

    $this->session->set_userdata("admin", $user[0]["admin"]);


推荐答案

您不能使用辅助文件中的$ this 只是辅助文件(那里没有类)。要使用控制器的 $ this 提供的功能,您必须执行以下操作:

You can't use $this inside a helper as a helper file is just a collection of functions (no class there). To use the functionality provided by $this of controller, you'll have to do:

$ci = & get_instance();
$ci->session->set_userdata("admin", $user[0]["admin"]);

这篇关于Codeigniter调用非对象上的成员函数set_userdata()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆