CI 묻고 답하기

제목 쿼리스트링 사용시 변수가 1개 일때는 어떻하나요?
글쓴이 kimga 작성시각 2010/05/30 00:51:16
댓글 : 7 추천 : 0 스크랩 : 0 조회수 : 25695   RSS
http://codeigniter-kr.org/tip/view/426/page/1/q/MY_Input
위의 라이브러리를 현재 사용중입니다.

사용하다보니 'http://foobar.com/abc?temp=1' 은  에러가 나고


'http://foobar.com/abc?temp=1&temp2=1' 이렇게 중간에 &가 들어가야지만 인식이 되더군요.

변수가 1개만 주어져도 에러가 안나고 처리될수 있는 방법이 없을까요?

 다음글 mysql 함수 now() 입력 질문 (2)
 이전글 $_POST['x'] , $_POST['y'] ... (2)

댓글

변종원(웅파) / 2010/05/30 01:03:04 / 추천 0
아래 부분만 if문으로 한개만 있을 경우 처리하시면 됩니다.

$params = explode("&", $_SERVER["REDIRECT_QUERY_STRING"]);
kimga / 2010/05/30 01:34:29 / 추천 0
저로선 굉장히 난해한 답변이네요;

혹시  알아듣기 쉽게 설명해주시거나 저 라이브러리를 어떻게 고쳐야 되는지 알려주실수  있을까요 
배강민 / 2010/05/30 09:38:50 / 추천 0

흠.. 테스트해봤는데.. 정상동작하는데요....?

null, a=1, a=1&b=2 이 3가지 테스트해봤는데...
 

mycastor / 2010/05/30 11:14:06 / 추천 0
에러가 발생하나요? 딱히 에러가 발생할 부분이 없는데요..

explode 함수의 경우 특정 delimiter 가 없는 경우

해당 문자열을 반환받는 변수의 0번으로 들어가게됩니다.

혹시나 아직 해결전이시라면 어떠한 에러가 발생하는지 말씀해주세요.
앤드그리고 / 2010/05/31 10:48:29 / 추천 0
저도 같은 문제가 있었는데, URI 클래스를 확장해서 해결했습니다.
해당 문제에 대한 해결책은
http://codeigniter.com/forums/viewthread/47192/#226591
여기를 참고했습니다.

아래 코드는 제가 확장해서 사용하고 있는 URI 클래스입니다.
51번째 줄
// url에 인자가 하나만 있을경우 컨트롤러를 제대로 찾지 못하는 문제 때문에, 위치를 이동합니다.
부분이 수정 내용입니다.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * URI Class
 *
 * Parses URIs and determines routing
 *
 * @package        CodeIgniter
 * @subpackage    Libraries
 * @category    URI
 * @author        ExpressionEngine Dev Team
 * @link        http://codeigniter.com/user_guide/libraries/uri.html
 */
class MY_URI extends CI_URI {

    /**
     * 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/05/31 14:29:52 / 추천 0
kimga/ 1개일 경우 제대로 안나온다고 하시니 위 구문이 실제 쿼리스트링을 배열로 만드는 부분이라
if문으로 1개일때 처리와 그 이상일때 처리를 하면 된다고 답변 드린 겁니다.

설마 완전한 소스를 원하시는건 아니겠죠? ^^

kimga / 2010/06/07 23:54:36 / 추천 0

답변 정말 감사드립니다. 혼자서 헤매면서 아직도 해결 못하고 있었네요