질문
Q #11413
Session 클래스를 로드 할 때 생성자에 변수를 전달 할 수 있을까요?
왕기장군
2014-06-17 16:22:58
클래스는 아래처럼 생겼습니다.
오리지널 소스는 $sess_namespace 의 값을 config 에서 불러서 쓰도록 되어 있는데요..
전.. 로그인할 때 $sess_namespace 의 값을 할당해 주고 싶습니다.
어떻게 하면 될까요?
오리지널은 initialize() 인데 제가 initialize($sess_name = '') 라고 수정을 해 놓았습니다.
이 세션클래스는 autoload 에서
$autoload['libraries'] = array('database', 'common', 'session', 'test');
ㅇㅣ렇게 로드하고 있는데요..
제가 initialize 나
혹은 set_userdata 시점에 값을 재 할당 할 수 있는 방법은 없을까요..
class MY_Session
{
protected $sess_namespace = '';
protected $ci;
protected $store = array();
protected $flashdata_key = 'flash';
private $_config = array();
/**
* Constructor
*
* @access public
* @param array config preferences
*
* @return void
**/
public function __construct()
{
$this->ci = get_instance();
// Default to 2 years if expiration is "0"
$this->_expiration = 60 * 60 * 24 * 365 * 2;
$this->initialize();
// Delete 'old' flashdata (from last request)
$this->_flashdata_sweep();
// Mark all new flashdata as old (data will be deleted before next request)
$this->_flashdata_mark();
}
/**
* Initialize the configuration options
*
* @access private
* @return void
*/
private function initialize($sess_name = '')
{
// $this->ci->load->config('session');
$this->_config = array();
$prefs = array(
'sess_cookie_name',
'sess_expire_on_close',
'sess_expiration',
'sess_match_ip',
'sess_match_useragent',
'sess_time_to_update',
'cookie_prefix',
'cookie_path',
'cookie_domain',
'cookie_secure',
'cookie_httponly'
);
foreach ($prefs as $key) {
$this->_config[$key] = $this->ci->config->item($key);
}
// 수정한 부분...
$sess_namespace = $sess_name != '' ? $sess_name : $this->ci->config->item('sess_namespace');
$this->_config = array_merge(
array(
'sess_namespace' => $sess_namespace
),
$this->_config
);
foreach ($this->_config as $key => $val) {
if (method_exists($this, 'set_'.$key)) {
$this->{'set_'.$key}($val);
} elseif (isset($this->$key)) {
$this->$key = $val;
}
}
... ㅇㅣ하 생략
// $this->ci->load->config('session'); $this->ci->load->config('my_session');