Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter cannot load libraries

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

However I have discovered even with a clean install of codeigniter I am unable to load libraries such as the Session library or even the Migration 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.

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

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.

Does anyone have any ideas

OS: Windows 8.1

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

Codeigniter: 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.

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.

Also for the initial problem if you are using the files driver 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.

like image 348
mdixon18 Avatar asked Apr 03 '15 12:04

mdixon18


People also ask

How to load library in CodeIgniter view?

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

How to use library function in CodeIgniter?

To access CodeIgniter's native resources within your library use the get_instance() function. This function returns the CodeIgniter super object. Normally from within your controller functions you will call any of the available CodeIgniter functions using the $this construct: $this->load->helper('url');

How to use get_ instance in CodeIgniter?

First, assign the CodeIgniter object to a variable: $CI =& get_instance(); Once you've assigned the object to a variable, you'll use that variable instead of $this : $CI =& get_instance(); $CI->load->helper('url'); $CI->load->library('session'); $CI->config->item('base_url'); // etc.


2 Answers

Working code;

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

This allows to execute the script.

like image 124
Nill Avatar answered Oct 12 '22 01:10

Nill


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 worked

$config['sess_save_path'] = '/tmp'; 
like image 36
Tpojka Avatar answered Oct 12 '22 02:10

Tpojka