CI 묻고 답하기

제목 controllers 하위폴더 생성에 대해서
글쓴이 ci_beginne 작성시각 2009/09/30 15:08:42
댓글 : 3 추천 : 0 스크랩 : 0 조회수 : 27496   RSS
안녕하세요 ci 초보자입니다.

지금 개발 직전에 폴더 구조를 생성할려고 하는데

ci메뉴얼에 보면 컨트롤러들을  하위폴더로 구성하기가 있더라고요

그래서 적용시켜봤는데 하위폴더가 1단계만 적용이 되네요

예를 들면
dev.test.net/index.php/manage/test/lists   이 경우에는 잘 동작하는데
dev.test.net/index.php/manage/member/test/lists 와 같이 한단계 더 들어가면 404 error가 나오네요

하위폴더를 2~3단 생성할수는 없는건지요?
 다음글 질문과 답변에 올려주실때 준수하여 주세요.
 이전글 config 파일에서 library 사용하기 (4)

댓글

앤드그리고 / 2009/09/30 15:39:17 / 추천 0
안녕하세요...
저도 같은 고민을 하다가, Router 를 상속받아서 메소드를 다시 만들었습니다.

코드는 대략 아래와 같구요...
하위 폴더가 있으면, 다시 하위폴더가 있는지 검사를 하도록 재귀함수로 약간 변경을 했습니다.

class MY_Router extends CI_Router {
  
    /**
     * Validates the supplied segments.  Attempts to determine the path to
     * the controller.
     *
     * @access    private
     * @param    array
     * @return    array
     */    
    function _validate_request($segments)
    {
        // Does the requested controller exist in the root folder?
        if (file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
        {
            return $segments;
        }

        // Is the controller in a sub-folder?
        if (is_dir(APPPATH.'controllers/'.$this->fetch_directory().$segments[0]))
        {        
            // Set the directory and remove it from the segment array
            $this->_append_directory($segments[0]);
            $segments = array_slice($segments, 1);
            
            if (count($segments) > 0)
            {
                // Does the requested controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
                {
                    return $this->_validate_request($segments);
                }
            }
            else
            {
                $this->set_class($this->default_controller);
                $this->set_method('index');
            
                // Does the default controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
                {
                    $this->directory = '';
                    return array();
                }
            
            }

            return $segments;
        }

        // Can't find the requested controller...
        show_404($segments[0]);
    }

    /**
     *  Append the directory name
     *
     * @access  public
     * @param   string
     * @return  void
     */ 
    function _append_directory($dir)
    {
        $this->directory .= $dir.'/';
    }
}

ci세상 / 2009/09/30 17:39:10 / 추천 0
좋은 팁이네요^^ CI 코드실에도 등록을 함 해주세요 ~~
ci_beginne / 2009/10/01 10:40:35 / 추천 0
조영운님 감사합니다.
적용하니 너무 잘되네요^^