질문
Q #8589
controllers 하위폴더 생성에 대해서
ci_beginne
2009-09-30 15:08:42
안녕하세요 ci 초보자입니다.
지금 개발 직전에 폴더 구조를 생성할려고 하는데
ci메뉴얼에 보면 컨트롤러들을 하위폴더로 구성하기가 있더라고요
그래서 적용시켜봤는데 하위폴더가 1단계만 적용이 되네요
예를 들면
dev.test.net/index.php/manage/test/lists 이 경우에는 잘 동작하는데
dev.test.net/index.php/manage/member/test/lists 와 같이 한단계 더 들어가면 404 error가 나오네요
하위폴더를 2~3단 생성할수는 없는건지요?
저도 같은 고민을 하다가, 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.'/'; } }