본문 바로가기

컨트롤러에서 세션 사용시 나는 에러

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Main::$session

Filename: controllers/main.php

class Main extends CI_Controller

{

function Main()

{

parent::__construct();

}


//페이지 로드시 기본적으로 호출 되는 펑숑

function index()

{

if($this->session->userdata('userid')) 

{

}

}


}


 
session을 사용 하려고 하면 에러가 난다. 해결법은
autoload.php에 세션 로드 추가 해준다.
 
  

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


다시 리로드 했는데 또 아래와 같이 에러가 난다.

An Error Was Encountered

In order to use the Session class you are required to set an encryption key in your config file

 
 config.php에 encryption_key를 셋팅 해준다.

/*

|--------------------------------------------------------------------------

| Encryption Key

|--------------------------------------------------------------------------

|

| If you use the Encryption class or the Session class you

| MUST set an encryption key.  See the user guide for info.

|

*/

$config['encryption_key'] = 'nimjomjjang';