php Codeigniter 无法加载库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29431910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:24:28  来源:igfitidea点击:

Codeigniter cannot load libraries

phpcodeignitersession

提问by mdixon18

Initially, I thought I had a problem with loading libraries due to using Modular Extensions inside Codeigniter.

最初,我认为由于在 Codeigniter 中使用了模块化扩展,我在加载库时遇到了问题。

However I have discovered even with a clean install of codeigniter I am unable to load libraries such as the Session libraryor even the Migration library.

但是,我发现即使全新安装了 codeigniter,我也无法加载诸如Session library甚至迁移库之类的库。

I always get similar error messages usually to do with loading files.

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

Here is my error message I have when using the Session library.

这是我在使用 Session 库时收到的错误消息。

Note:If i don't use libraries everything works fine.

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

Error:

错误:

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

遇到 PHP 错误
严重性:警告
消息:mkdir() [function.mkdir]:无效参数
文件名:drivers/Session_files_driver.php
行号:117

回溯:
文件:index.php 行:301 功能:require_once

遇到未捕获的异常
类型:异常
消息:会话:配置的保存路径“不是目录,不存在或无法创建。

文件名:\system\libraries\Session\drivers\Session_files_driver.php
行号:119

回溯:
文件:index.php 行:301 功能:require_once

I feel like this is some form of permissions issue, but whether I am using AMPPS, MAMP (Windows) or XAMP I always get this problem.

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

Does anyone have any ideas

有没有人有任何想法

OS: Windows 8.1

操作系统:Windows 8.1

Webserver: AMPPS/MAMP(Windows)/XAMP - All have the problem.

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

Codeigniter: v3.0.0

:V3.0.0

Config:

配置

$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;


EDIT:

编辑

Resolved.

解决。

It's important now that you use the CI3 Documentation, When using the database method for sessions please ensure you use the updated SQL to create the table.

现在使用 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`)
);

As found here. I hope this helps anyone out with similar problems.

如发现here。我希望这可以帮助任何有类似问题的人。

Also for the initial problem if you are using the filesdriver please ensure you set the $config['sess_save_path']to something like 'ci_sessions'or wherever you wish to store. Please see @Tpojka answer for more information.

同样对于最初的问题,如果您正在使用files驱动程序,请确保您将其设置$config['sess_save_path']为类似'ci_sessions'或您希望存储的任何位置。请参阅@Tpojka 答案以获取更多信息。

采纳答案by Tpojka

Message:Session: Configured save path '' is not a directory, doesn't exist or cannot be created.

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

$config['sess_save_path'] = NULL;

Try to set this one.

尝试设置这个。

For me This one workred $config['sess_save_path'] = '/tmp';

对我来说,这是一个有效的 $config['sess_save_path'] = '/tmp';

回答by Nill

Working code;

工作代码;

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

This allows to execute the script.

这允许执行脚本。

回答by Vijay Jakhar

This Code is working for on my MACOS for session error :

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

You need to add this code into config.php file

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

you need to replace NULLwith sys_get_temp_dir()

你需要替换NULLsys_get_temp_dir()

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

My error was :

我的错误是:

Warning: Uncaught Exception: Session: Configured save path '' is not a directory, doesn't exist or cannot be created. in /Library/WebServer/Documents/ci/fuse/system/libraries/Session/drivers/Session_files_driver.php:138 Stack trace: #0 [internal function]: CI_Session_files_driver->open('', '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) #7 /Library/WebServe in /Library/WebServer/Documents/ci/fuse/system/libraries/Session/drivers/Session_files_driver.php on line 138

Fatal error: session_start(): Failed to initialize storage module: user (path: ) in /Library/WebServer/Documents/ci/fuse/system/libraries/Session/Session.php on line 143

警告:未捕获的异常:会话:配置的保存路径 '' 不是目录,不存在或无法创建。在 /Library/WebServer/Documents/ci/fuse/system/libraries/Session/drivers/Session_files_driver.php:138 堆栈跟踪:#0 [内部函数]:CI_Session_files_driver->open('', '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,

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

回答by Brijmohan Karadia

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

回答by zbrka

I also run into this problem today.

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

Thank you Sparky and Trojka, setting my config to use database instead file made my CI app working perfectly, both on my local server and live one.

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

Here is how:

方法如下:

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

There is MySQL for table creation in link Trojka posted.

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

回答by Himanshu Saini

From CI3 Docs: By default, the Files Driver will be used when a session is initialized, because it is the most safe choice and is expected to work everywhere (virtually every environment has a file system).

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

So default thing works good on windows environment but on mac and linux systems I have faced similar issues.

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

Thing that worked for me without switching to Database:

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

Step 1: create session directory with proper permissions:

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

Take care of apache username it varies like: www-data, _www, apache etc.

照顾好 apache 用户名,例如:www-data、_www、apache 等。

Step 2: Set absolute path for sess_save_path config: (Mine on Mac looked like below)

第 2 步:为 sess_save_path 配置设置绝对路径:(我在 Mac 上看起来如下所示)

$config['sess_save_path'] ='/Library/WebServer/Documents/App/ci_sessions/';