Live Brilliant

Codeigniter 쿼리스트링URL 과 세그먼트 URL 혼합 사용 하기 본문

개발은 핵찜이야/codeigniter

Codeigniter 쿼리스트링URL 과 세그먼트 URL 혼합 사용 하기

주인정 2012. 8. 3. 11:18

Codeigniter 쿼리스트링URL 과 세그먼트 URL 혼합 사용 하기


1. 세그먼트 기반 접근방식
예: example.com/product/search/test/2

2.쿼리스트링 접근방식
예: example.com/?c=product&m=search&pname=test&pid=2

위 두가지 동시에 사용하는 방법



Option 1: Mixing Globally(전역 적용)
To enable this globally, go to your application/config.php file, and look for $config['uri_protocol']variable and change it to:

$config['uri_protocol'] = "PATH_INFO";
After that, find the $config['enable_query_strings'] variable and change it to:
$config['enable_query_strings'] = TRUE;

Your application should now accept both segments and querystrings.
Option 2: Mixing Locally(특정 컨트롤러 적용)
If you don’t want to enable this capability across your whole application, you can restrict it to only the controllers you want.
You can do this by going to the 

application/config.php file and switching $config['enable_query_strings']back to ‘FALSE’.
$config['enable_query_strings'] = FALSE;
Leave the $config['uri_protocol'] as PATH_INFO
$config['uri_protocol'] = "PATH_INFO";

and then you can add this line to your controller’s contructor method

그리고 해당 컨트롤러 contructor 아래 내용 추가

parse_str($_SERVER['QUERY_STRING'],$_GET);
So if you do a test now, only the controller with the above line of code will be able to accept mixed segment and querystring URLs. 


 출처:  http://www.tech2grab.com/2011/02/codeigniter-mixing-segment-based-url.html

Comments