CI 묻고 답하기

제목 [초보]uri를 바꿔서 사용해 보기..
글쓴이 헛발이 작성시각 2010/03/23 15:44:59
댓글 : 7 추천 : 0 스크랩 : 0 조회수 : 21323   RSS
config.php에서요..
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] 	= 'c';
$config['function_trigger'] 	= 'm';
$config['directory_trigger'] 	= 'd'; // experimental not currently in use
이렇게 TRUE로 변경하고 URL에서

http://도메인/모듈명/콘트롤러/메소드?id=1

이렇게 하면 안되나요?

모듈명, 콘트롤명, 메소드명은 그대로 사용하고 id부터만 id=1 이런식으로 하고 싶은데요...
그냥 TRUE만으로는 안되나요 ?

 다음글 죄송한데 질문하나만 드릴께요~ (2)
 이전글 load->view 할때 다른 모듈에서 가져오기 (5)

댓글

변종원(웅파) / 2010/03/23 16:09:01 / 추천 0
안됩니다.
tip게시판에 보시면 편법으로 사용할 수 있게 mycaster님이 올리신게 최근에 있습니다.
아니면 tip게시판에서 제 닉으로 검색해서 주소관련 글 참고하셔서 적용하시면 됩니다.

http://도메인/모듈/컨트롤러/?method=메소드&var=변수&sp=1 형식입니다.
헛발이 / 2010/03/23 16:51:47 / 추천 0
아 그렇군요... 감사합니다..
헛발이 / 2010/03/23 18:15:25 / 추천 0
config에서 이렇게만 해선 안되나봐요?

$config['uri_protocol']	= "REQUEST_URI";

일단 이렇게만 해서
http://도메인/test/test/?id=1 이렇게 해도
이런 에라가 나는데요...

An Error Was Encountered

The URI you submitted has disallowed characters.


변종원(웅파) / 2010/03/23 21:09:09 / 추천 0

헛발이님 물음표때문입니다.
config.php의 주소표시줄에 쓸수있는 문자셋에 ?를 추가해주셔야 합니다.
에러메세지에도 나와있죠. 허용되지 않는 문자가 주소에 있다고.. ^^

헛발이 / 2010/03/23 21:30:50 / 추천 0
아하~
앤드그리고 / 2010/03/24 14:34:45 / 추천 0
안녕하세요. 혹시나해서 덧붙입니다.
segment 와 querystring 을 같이 사용할 경우,
querystring 에 인자가 하나만 있을경우 404 에러가 발생하는 문제에 대해서 덧붙입니다.

URI 클래스에 _fetch_uri_string() 라는 메소드가 있는데 이 메소드를 약간 수정해서 사용하면 해당 문제를 해결할 수 있습니다.


MY_URI.php
/**
     * Get the URI String
     *
     * @access    private
     * @return    string
     */
    function _fetch_uri_string()
    {
        if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
        {
            // Is there a PATH_INFO variable?
            // Note: some servers seem to have trouble with getenv() so we'll test it two ways
            $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
            if (trim($path, '/') != '' && $path != "/".SELF)
            {
                $this->uri_string = $path;
                return;
            }

            // No PATH_INFO?... What about QUERY_STRING?
            $path =  (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
            if (trim($path, '/') != '')
            {
                $this->uri_string = $path;
                return;
            }

            // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists?
            $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');
            if (trim($path, '/') != '' && $path != "/".SELF)
            {
                // remove path and script information so we have good URI data
                $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path);
                return;
            }

            // url에 인자가 하나만 있을경우 컨트롤러를 제대로 찾지 못하는 문제 때문에, 위치를 이동합니다.
            // If the URL has a question mark then it's simplest to just
            // build the URI string from the zero index of the $_GET array.
            // This avoids having to deal with $_SERVER variables, which
            // can be unreliable in some environments
            if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')
            {
                $this->uri_string = key($_GET);
                return;
            }
            
            // We've exhausted all our options...
            $this->uri_string = '';
        }
        else
        {
            $uri = strtoupper($this->config->item('uri_protocol'));

            if ($uri == 'REQUEST_URI')
            {
                $this->uri_string = $this->_parse_request_uri();
                return;
            }

            $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);
        }

        // If the URI contains only a slash we'll kill it
        if ($this->uri_string == '/')
        {
            $this->uri_string = '';
        }
    }

변종원(웅파) / 2010/03/24 15:48:54 / 추천 0
조영운/ 네 확장해서 처리하셨군요. 저도 비슷한 문제를 겪어서...
전 주소처리 함수를 따로 하나 만들어서 사용했습니다. 그안에서 처리를 했구요. ^^