Codeigniter 在非对象上调用成员函数 set_userdata()

发布于 2024-12-21 02:17:01 字数 577 浏览 0 评论 0原文

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

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< /a>

我试图弄清楚 php 版本是否是问题所在。该网站在旧服务器上运行良好,而新服务器没有 php4 作为选项。

破坏的具体代码行是:

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

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

Code in full located in the link below

https://gist.github.com/1474173

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.

The specific code line thats breaking is:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

楠木可依 2024-12-28 02:17:01

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

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

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"]);
无名指的心愿 2024-12-28 02:17:01

$CI =&获取实例();

$CI->加载->library('session');

$CI =& get_instance();

$CI->load->library('session');

无力看清 2024-12-28 02:17:01

您是否在构造函数中以及在parent::__construct() 指令之后加载会话库?

Are you loading the session librairy in the constructor and after the parent::__construct() instruction?

倾其所爱 2024-12-28 02:17:01

您正在使用 Codeigniter 的默认配置。
问题是:没有完成数据库配置!
您必须在此处输入:\YOUR_APPLICATION_NAME\application\config\database.php,

并且必须使用文本编辑器打开此文件。

设置以下变量即可完成:

$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "127.0.0.1";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "NameOfYourDatabase";

You are using the default configuration of Codeigniter.
The problem is: NO DATABASE CONFIGURATION DONE!
You must enter here: \YOUR_APPLICATION_NAME\application\config\database.php

and you must open this file with a text editor.

Set the following variables and you are done:

$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "127.0.0.1";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "NameOfYourDatabase";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文