질문 Q #16226
ci 3.0 rest api route 질문드립니다.
0년차 2016-12-16 18:23:57
$route['api/v1/([a-zA-Z]+)/(\d+)']['([a-zA-Z]+)'] = function($class, $key, $method){
    $class  = $class ? strtolower($class) : exit;
    $method = $method ? strtolower($method) : "get";
    $key    = strtolower($key);
    $path   = "api/vi/".$class."/".$class."_".$method."/".$key;
    
    return $path;
};

 

이런식으로 라우팅을 설정하려고 하는데

제가 정규표현식이나 라우팅 규칙에 대한 부분에 대한 지식이 부족하여..

잘 안되고 있네요..

염치없지만 조언 부탁드립니다.

답변 1
#1 닉 2016-12-20 12:00:58

저랑 url 작성이 비슷하네요 ㅋ 저는 apivi/ 이렇게 시작해요,,, ㅋㅋ

https://github.com/chriskacerguis/codeigniter-restserver 전 이거로 api 만들었어요...

질문의 요지가 클래스 메소드 키를 알고 싶으신 건가요??

routes에서 $this를 출력해보면, object(CI_Router)라고 나오고 uri 객체가 있으니 uri->segment를 통해서 매핑하면 될듯해요..