Codeigniter无法加载库

时间:2015-04-03 12:07:07

标签: php codeigniter

最初,由于在Codeigniter中使用Modular Extensions,我认为我在加载库时遇到了问题。

但是我发现即使安装了codeigniter,我也无法加载Session library甚至迁移库等库。

我总是会收到类似的错误消息,通常与加载文件有关。

这是我在使用会话库时出现的错误消息。

注意:如果我不使用库,一切正常。

错误:

 A PHP Error was encountered    
 Severity: Warning    
 Message: mkdir() [function.mkdir]: Invalid argument    
 Filename: drivers/Session_files_driver.php    
 Line Number: 117

 Backtrace:    
 File: index.php
 Line: 301
 Function: require_once

 An uncaught Exception was encountered    
 Type: Exception    
 Message: Session: Configured save path '' is not a directory, doesn't exist or cannot be created.

 Filename: \system\libraries\Session\drivers\Session_files_driver.php    
 Line Number: 119

 Backtrace:    
 File: index.php
 Line: 301
 Function: require_once

我觉得这是某种形式的权限问题,但无论我使用AMPPS,MAMP(Windows)还是XAMP,我总是遇到这个问题。

有没有人有任何想法

操作系统:Windows 8.1

网络服务器:AMPPS / MAMP(Windows)/ XAMP - 一切都有问题。

Codeigniter :v3.0.0

配置

$config['sess_driver'] = 'files';
$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;
$config['sess_regenerate_destroy'] = FALSE;

修改

解决。

现在使用CI3文档非常重要,在使用数据库方法进行会话时,请确保使用更新的SQL来创建表。

CREATE TABLE IF NOT EXISTS `ci_sessions` (

        `id` varchar(40) NOT NULL,
        `ip_address` varchar(45) NOT NULL,
        `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
        `data` blob NOT NULL,
        PRIMARY KEY (id),
        KEY `ci_sessions_timestamp` (`timestamp`)
);

找到here。我希望这可以帮助任何有类似问题的人。

如果您使用的是files驱动程序,请注意初始问题,请确保将$config['sess_save_path']设置为'ci_sessions'或您希望存储的位置。有关更多信息,请参阅@Tpojka答案。

6 个答案:

答案 0 :(得分:78)

工作代码;

$config['sess_save_path'] = sys_get_temp_dir();

这允许执行脚本。

答案 1 :(得分:10)

  

消息:会话:已配置的保存路径''不是目录,不存在或无法创建。

$config['sess_save_path'] = NULL;

尝试设置此项。

答案 2 :(得分:6)

Step1 : open config.php and create a session folder with 0755 permission.
Step2 : update below code variable 
$config['sess_save_path'] =  __DIR__.'/session'; 

答案 3 :(得分:6)

此代码适用于我的MACOS会话错误:

您需要将此代码添加到config.php文件

您需要将NULL替换为sys_get_temp_dir()

$config['sess_save_path'] = sys_get_temp_dir();

我的错误是:

  

警告:未捕获异常:会话:已配置的保存路径''不是目录,不存在或无法创建。在/Library/WebServer/Documents/ci/fuse/system/libraries/Session/drivers/Session_files_driver.php:138堆栈跟踪:#0 [内部功能]:CI_Session_files_driver->打开('','ci_session')#1 /Library/WebServer/Documents/ci/fuse/system/libraries/Session/Session.php(143):session_start()#2 /Library/WebServer/Documents/ci/fuse/system/core/Loader.php(1281) :CI_Session-> __ construct()#3 /Library/WebServer/Documents/ci/fuse/system/core/Loader.php(1174):CI_Loader-> _ci_init_library('Session','CI_',NULL,'session ')#4 /Library/WebServer/Documents/ci/fuse/system/core/Loader.php(1037):CI_Loader-> _ci_load_stock_library('Session','Session /',NULL,NULL)#5 / Library / WebServer / Documents / ci / fuse / system / core / Loader.php(1082):CI_Loader-> _ci_load_library('Session',NULL,NULL)#6 / Library / WebServer / Documents / ci / fuse / system / core / Loader.php(218):CI_Loader-> _ci_load_library('Session',NULL,NULL)#Library / WebServe in / Library / WebServer / Documents / ci / fuse / system / libraries / Session / d第138行的rivers / Session_files_driver.php

     

致命错误:session_start():无法在第143行的/Library/WebServer/Documents/ci/fuse/system/libraries/Session/Session.php中初始化存储模块:user(path:)

答案 4 :(得分:5)

我今天也遇到了这个问题。

感谢Sparky和Trojka,将我的配置设置为使用数据库而不是文件使我的CI应用程序在我的本地服务器和现场服务器上完美运行。

以下是:

$config['sess_driver'] = 'database';       // changed from file
$config['sess_save_path'] = 'ci_sessions'; // table name

链接Trojka发布了用于创建表的MySQL。

答案 5 :(得分:2)

来自CI3文件: 默认情况下,会话初始化时将使用文件驱动程序,因为它是最安全的选择,并且可以在任何地方工作(几乎每个环境都有文件系统)。

因此默认的东西在Windows环境中运行良好,但在mac和linux系统上,我遇到了类似的问题。

在没有切换到数据库的情况下对我有用的东西:

步骤1:使用适当的权限创建会话目录:

mkdir /<path to your application directory>/ci_sessions/
chmod 0700 /<path to your application directory>/ci_sessions/
chown _www /<path to your application directory>/ci_sessions/

请注意apache用户名,例如:www-data,_www,apache等。

步骤2:设置sess_save_path配置的绝对路径: (我的Mac看起来如下)

$config['sess_save_path'] ='/Library/WebServer/Documents/App/ci_sessions/';
相关问题