【问题标题】:Unable to load the requested class: Session Codeigniter 3无法加载请求的类:Session Codeigniter 3
【发布时间】:2015-05-18 16:50:28
【问题描述】:

尝试在 Codeigniter 中加载 Session 库。这似乎显然是正确的,但实际上是行不通的。 这是配置文件的一部分:

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;

同样,ncryption 密钥变量已经设置。此外,CI 3 文档无法为我提供解决此问题的方法。


我已经尝试过:

  1. 将“sess_save_path”变量设置为“ci_sessions”
  2. 检查文件夹权限
  3. 检查表 'ci_sessions' 是否存在
  4. 使用自动加载器类
  5. 使用大写 S 的类名

有点奇怪,但是config说:

 /*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/www folder
| or in your application/www folder.
|
| Prototype:
|
|   $autoload['www'] = array('database', 'email', 'session');
|
| You can also supply an alternative library name to be assigned
| in the controller:
|
|   $autoload['www'] = array('user_agent' => 'ua');
*/

这是自动加载器的代码:

// Load www
        if (isset($autoload['www']) && count($autoload['www']) > 0)
        {
            // Load the database driver.
            if (in_array('database', $autoload['www']))
            {
                $this->database();
                $autoload['www'] = array_diff($autoload['www'], array('database'));
            }

            // Load all other www
            foreach ($autoload['www'] as $item)
            {
                $this->library($item);
            }
        }

【问题讨论】:

  • 我重新安装了 CI,但没有任何改变
  • 你为什么有$config['sess_save_path'] = NULL;? ,你试过$config['sess_save_path'] = 'ci_sessions'吗?
  • 您是否设置了加密密钥? $config['encryption_key'] = 'anything_here';
  • 它在那里做什么?对于 CI3,它应该在:\system\libraries\Session\Session.php
  • 这很奇怪,因为你的 cmets 说 $autoload['www'] ... 你从哪里下载的?你是从codeigniter.com 做的吗?

标签: php codeigniter session


【解决方案1】:

以下是您应该尝试的列表:

  1. 确保在 autload.php 中加载会话库:$autoload['libraries'] = array('session');

  2. 确保您的加密密钥已在 cofing.php 中设置:$config['encryption_key'] = 'anything_here'

  3. 确保您的数据库表名为 ci_sessions 并且您的 sess_save_path 设置为该名称:$config['sess_save_path'] = "ci_sessions"

  4. 如果您使用的是 Unix/Linux,请确保以大写字母加载您的库:$autoload['libraries'] = array('Session');

  5. 如果不起作用,请检查您是否从 http://www.codeigniter.com/download 下载并安装了正确的 CI3 文件

【讨论】:

  • 我什么都试过了,但问题还没有解决
  • 没问题的兄弟,虽然很奇怪.. 你的初始安装文件是从哪里得到的?
  • 其实我也不知道。已被其他程序员下载。
【解决方案2】:

你需要这样做

config/autoload.php 文件并确保您有此文件以在 Code Igniter 3 中加载会话。

$autoload['drivers'] = array('session');

确保您已正确安装 ci3,并且没有丢失任何库文件和类。我喜欢在安装 ci 时使用 git 或 composer 来跟踪更改,或者您可以获取 zip 或 .gz 并将其解压缩以使用。

【讨论】:

  • 我想你的意思是:$autoload['libraries'] = array('session'); 不是$autoload['drivers']
  • $autoload['libraries'] = array('session') 给出相同的结果:无法加载请求的类:会话
  • 在配置中将随机密钥放在 $config['encryption_key'] 并检查您的文件夹权限。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-23
  • 2013-05-14
  • 1970-01-01
  • 2012-05-25
  • 2018-07-20
  • 1970-01-01
  • 2016-05-06
相关资源
最近更新 更多