CI 묻고 답하기

제목 Session 클래스를 로드 할 때 생성자에 변수를 전달 할 수 있을까요?
글쓴이 왕기장군 작성시각 2014/06/17 16:22:58
댓글 : 3 추천 : 0 스크랩 : 0 조회수 : 12455   RSS
클래스는 아래처럼 생겼습니다.

오리지널 소스는  $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;
            }
        }

... ㅇㅣ하 생략
 다음글 마냐 공개보드 소스 및 링크 에러 (2)
 이전글 route관련 질문드립니다. (3)

댓글

한대승(불의회상) / 2014/06/17 17:03:42 / 추천 0
아래 처럼 바꾸고 my_session.php를 config 폴더에 만들면 어떨까요?
 
// $this->ci->load->config('session');
$this->ci->load->config('my_session');
왕기장군 / 2014/06/17 18:16:23 / 추천 0
어렵네요...  세션 클래스 파일을 로딩할 때마다 변수에 내용을 채워줘야 하는데
한대승(불의회상) / 2014/06/18 08:56:24 / 추천 0
전역변수를 사용해 보세요.