기존 2.x 버전때에는
hook에서 컨트롤러 요청전['pre_controller'] extends CI_Controller로 상속받으면 세션이 정상적으로 로드되었습니다.
기존 3.x 버전때에는
hook에서 컨트롤러 요청전['pre_controller'] extends CI_Controller로 상속받고 세션을 로드하면 로드가 되지 않습니다.
구글링을 통해
private $CI;
function __construct()
{
$this->CI =& get_instance();
if($this->CI === NULL){
new CI_Controller();
$this->CI =& get_instance();
}
if(!isset($this->CI->session)){ //Check if session lib is loaded or not
$this->CI->load->library('session'); //If not loaded, then load it here
}
}
다음과 같이 작성하면 세션을 사용할수있었지만
컨트롤러 요청전이아닌 컨트롤러 요청 후입니다.
세션이 드라이버로 옮겨져서이다 등 여러 변화된 이슈가 있었는데 도저히 이유를 모르겠습니다......ㅠㅠㅠ
컨트롤러 요청전인데 컨트롤러 객체를 어디서 가져오죠? ^^
CI의 객체는 load class 에서 전부 DI 주입식으로 이루어 집니다.
컨트롤러 요청전이라는 것은 컨트롤러가 로드되지 전이라는 의미입니다.
컨트롤러 객체를 가져와야 하는 이유는 모르겠으나,오히려 컨틀롤러가 로드된 후에 반대로 트러블이 생기기도 합니다.
get_instance() 로 프레임워크 객체를 가져온후 사용하면 됩니다.
// CI 컨트롤러 객제 $ci = &get_instance(); // 세션 로드 $ci->load->library('session'); // 세션 사용 $ci->session->userdata('item'); . . .